in_array() | JavaScriptSource

in_array()

Benoit Asselin Oct 24, 2007

General

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.


Notes

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.

Head

Paste this code into your script.


Leave a Response

(2 comments)

You will need to submit your question to the [a href="http://www.webdeveloper.com/forum/forumdisplay.php?f=3"]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