filter array and return object code example
Example 1: how to filter an array of objects in javascript
let arr=[{id:1,title:'A', status:true}, {id:3,title:'B',status:true}, {id:2, title:'xys', status:true}];
let x = arr.filter((a)=>{if(a.title=='B'){return a}});
console.log(x)
Example 2: javascript array filter
var numbers = [1, 3, 6, 8, 11];
var lucky = numbers.filter(function(number) {
return number > 7;
});
Example 3: javascript array filter
var newArray = array.filter(function(item) {
return condition;
});
Example 4: js filter items by index
let newArray = arr.filter(callback(element[, index, [array]])[, thisArg])