js filter return value code example
Example 1: filter in js
const filterThisArray = ["a","b","c","d","e"]
console.log(filterThisArray)
const filteredThatArray = filterThisArray.filter((item) => item!=="e")
console.log(filteredThatArray)
Example 2: filter out arrays js
let newArray = array.filter(function(item) {
return condition;
});
Example 3: javascript array filter
var newArray = array.filter(function(item) {
return condition;
});
Example 4: filter array by keyword
var data = [
{email: "[email protected]",nama:"User A", Level:"Super Admin"},
{email: "[email protected]",nama:"User B", Level:"Super Admin"},
{email: "[email protected]",nama:"User C", Level:"Standart"},
{email: "[email protected]",nama:"User D", Level:"Standart"},
{email: "[email protected]",nama:"User E", Level:"Admin"},
{email: "[email protected]",nama:"User F", Level:"Standart"}
];
var filter = "Level";
var keyword = "Standart";
var filteredData = data.filter(function(obj) {
return obj[filter] === keyword;
});
console.log(filteredData);