xxxxxxxxxx
<html>
<head>
<meta name="description" content="filter multi-directional array with an array value." />
<script src="https://jashkenas.github.io/underscore/underscore-min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
// filter multi-directional array with an array value.
var array = [
{'name':'one', "age":'3'},
{'name':'two', "age":'1'},
{'name':'three', "age":'3'},
{'name':'four', "age":'1'},
{'name':'one', "age":'7'},
{'name':'one', "age":'5'},
{'name':'one', "age":'7'},
{'name':'one', "age":'8'},
{'name':'one', "age":'7'},
{'name':'one', "age":'11'},
{'name':'one', "age":'7'}
];
var filterarray = ['7', '8'];
var result = _.filter(array, function(item){
// _filter will pass if the function return true
return filterarray.indexOf(item.age) != -1;
// Returns the index at which value can be found in the array, or -1 if value is not present in the array.
});
console.log(result);
</script>
<script id="jsbin-source-html" type="text/html">
<html>
<head>
<meta name="description" content="filter multi-directional array with an array value." />
<script src="//jashkenas.github.io/underscore/underscore-min.js"><\/script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html></script>
<script id="jsbin-source-javascript" type="text/javascript">// filter multi-directional array with an array value.
var array = [
{'name':'one', "age":'3'},
{'name':'two', "age":'1'},
{'name':'three', "age":'3'},
{'name':'four', "age":'1'},
{'name':'one', "age":'7'},
{'name':'one', "age":'5'},
{'name':'one', "age":'7'},
{'name':'one', "age":'8'},
{'name':'one', "age":'7'},
{'name':'one', "age":'11'},
{'name':'one', "age":'7'}
];
var filterarray = ['7', '8'];
var result = _.filter(array, function(item){
// _filter will pass if the function return true
return filterarray.indexOf(item.age) != -1;
// Returns the index at which value can be found in the array, or -1 if value is not present in the array.
});
console.log(result);
</script></body>
</html>
Modified http://jashkenas.github.io/underscore/underscore-min.js to a secure url
https://jashkenas.github.io/underscore/underscore-min.js
https://jashkenas.github.io/underscore/underscore-min.js