js filter arra og object by filter 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 filter array of objects by id
const myArray = [{id: 1, name:'pipi'}, {id: 2, name:'popo'}];
const id = 2;
const variableOne = myArray.filter(itemInArray => itemInArray.id === id);
console.log(cariableOne[0].name);
Example 3: array filter
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.length > 6);
console.log(result);