From jQuery JavaScript Library
« Back to Utilities
jQuery.inArray( value, array )
Determine the index of the first parameter in the Array (-1 if not found).
Arguments:| value | Any | |
|---|
| Value to see if it exists in the array. |
| array | Array | |
|---|
| Array to look through for the value. |
Examples:| Name | Type |
var arr = [ 4, "Pete", 8, "John" ];
$("span:eq(0)").text(jQuery.inArray("John", arr));
$("span:eq(1)").text(jQuery.inArray(4, arr));
$("span:eq(2)").text(jQuery.inArray("David", arr));
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="../jquery-latest.js"></script>
<script>
$(document).ready(function(){
var arr = [ 4, "Pete", 8, "John" ];
$("span:eq(0)").text(jQuery.inArray("John", arr));
$("span:eq(1)").text(jQuery.inArray(4, arr));
$("span:eq(2)").text(jQuery.inArray("David", arr));
});
</script>
<style>
div { color:blue; }
span { color:red; }
</style>
</head>
<body>
<div>"John" found at <span></span></div>
<div>4 found at <span></span></div>
<div>"David" found at <span></span></div>
</body>
</html>