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}]; //find where title=B let x = arr.filter((a)=>{if(a.title=='B'){return a}}); console.log(x)//[{id:3,title:'B',status:true}]
how to filter an array by list of objects in javascript
var array = ['Jane','Donna','Jim','Kate'] var objects = [{name:'Jane', age:25},{name:'Jim', age:30}] //finds the items in the array that have names within the array of objects. var filtered = array.filter(r => objects.findIndex(obj => obj.name == r) > -1 ) console.log(filtered)
javascript filter array of objects by array
var arr = [1,2,3,4], brr = [2,4], res = arr.filter(f => !brr.includes(f)); console.log(res);
Source: stackoverflow.com
javascript filter array of objects
let people = [ { name: "Steve", age: 27, country: "America" }, { name: "Jacob", age: 24, country: "America" } ]; let filteredPeople = people.filter(function (currentElement) { // the current value is an object, so you can check on its properties return currentElement.country === "America" && currentElement.age < 25; }); console.log(filteredPeople); // [{ name: "Jacob", age: 24, country: "America" }]
Source: sebhastian.com
how to filter list of objects by an array in javascript
var array = ['cat','dog','fish','goat'] var objects = [{pet:'cat', color:'brown'},{pet:'dog', color:'black'},{pet:'gecko', color:'green'}] //finds the objects that match something in the list with the key pet. var filteredObjects = objects.filter(function(obj){ return array.indexOf((obj.pet).toString()) > -1; }); console.log(filteredObjects)
javascript array filter elements greater than
function isGreater(element, index, array) { return (element >= 10); } let testElemets = [12, 5, 8, 130, 44].filter(isGreater); console.log("Test Value : " + testElemets );