JQuery Array in Array

From CoderLearner
Jump to: navigation, search

jQuery Find Array Element

Uses inArray() function to find the element index within array.

Syntax $.inArray()

  • seek is the element to seek within array
  • array is the array
 
jQuery.inArray(seek,array);

Example 1

This returns the index of the element in the array.

$(document).ready(function() {
	var myList =[1,5,6,23,53];		
	alert(jQuery.inArray(53,myList));
});

Output

It is in the last index.

4

Example 2

$(document).ready(function() {
	var myList =['apple','toshiba','nokea','lcd'];		
	alert(jQuery.inArray('nokea',myList));
});

output

2