in_array() | JavaScriptSource


Benoit Asselin Oct 24, 2007


This snippet searches an array for a pre-specified element and returns 'true' if it's found, 'false' if it's not found. It functions like the in_array() in PHP.


Usage example:

var v_array = [ 5, 10, 15, 20, 25];
document.writeln(v_array.in_array(10)); // will return true
document.writeln(v_array.in_array(11)); // will return false

Source Code

Paste this source code into the designated areas.


Paste this code into your script.

Leave a Response


You will need to submit your question to the [a href=""]JavaScript Forum[/a] for further help.

Lee Oct 26, 2007

How to add or minus two numbers in text field for Example: text1 10 or any numbers var x, text2 20 or any numbers var y text3 shows a result 30[br /][br /]Thanks in advance

Juma Gull Arab Oct 25, 2007