Sometimes we need to check if a particular string exists in an array or not, we can do this by using inArray() method of jQuery very easily.
Example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Demo</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<p id="message"></p>
<script>
var arr = [ "Canada", "London", "India" ];
$("#message").text(jQuery.inArray( "India", arr ));
</script>
</body>
</html>
Hope this will help you :)
0 Comment(s)