Javascript examples for Array Operation:Array Search
Match and search Array value and return index with indexOf
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=( function() {/* w ww.j a v a 2 s . c o m*/ var arr = ['a', 'b', 'c', 'a']; function count(books, pattern) { var results = []; for (var index in arr) { if (arr[index] === pattern) { results.push(index); } } return results; } console.log(count(arr, 'a')); }); </script> </head> <body> </body> </html>