Grep an array by element value in jQuery
Description
The following code shows how to grep an array by element value.
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 ww w .j a v a 2 s . co m-->
var arr = [ 1, 3, 5, 7 ,5 ,6 ,7,9];
arr = jQuery.grep(arr, function( i){
return (i > 4);
});
alert(arr.join(", "));
});
</script>
</head>
<body>
<body>
<p></p>
</body>
</html>
The code above generates the following result.