Grep array for element value and index
Description
The following code shows how to grep an array by checking element value and index.
Example
<html>
<head>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {<!--from w ww .j a v a 2 s .c o m-->
var arr = [ 1, 3, 5, 7, 5, 6, 7, 9 ];
arr = jQuery.grep(arr, function(value, index) {
return (value != 6 && index > 4);
});
document.writeln(arr.join(", "));
});
</script>
</head>
<body>
<p></p>
</body>
</html>