Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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}]
Comment

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" }]
Comment

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)
Comment

Filter Array of Objects with Array of Objects

const myArray = [{ userid: "100", projectid: "10", rowid: "0" }, { userid: "101", projectid: "11", rowid: "1"}, { userid: "102", projectid: "12", rowid: "2" }, { userid: "103", projectid: "13", rowid: "3" }, { userid: "101", projectid: "10", rowid: "4" }];
const myFilter = [{ userid: "101", projectid: "11" }, { userid: "102", projectid: "12" }, { userid: "103",  projectid: "11"}];

const myArrayFiltered = myArray.filter((el) => {
  return myFilter.some((f) => {
    return f.userid === el.userid && f.projectid === el.projectid;
  });
});

console.log(myArrayFiltered);
Comment

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);
Comment

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)
Comment

filter array inside array of objects javascript

const initialState = [
     {id:1 ,name: 'Product A', image: 'pic-001.jpg', tags: ['nature', 'camping', 'outdoor']},
     {id:2 ,name: 'Product B', image: 'pic-002.jpg', tags: ['winter', 'hiking', 'camping', 'snow']},
     {id:3 ,name: 'Product C', image: 'pic-003.jpg', tags: ['vacation', 'family', 'kids', 'river', 'lake', 'fishing']}
];

const filterByTags = ['nature', 'family'];

const filterByTagSet = new Set(filterByTags);

const result = initialState.filter((o) => 
  o.tags.some((tag) => filterByTagSet.has(tag))
);

console.log(result);
 Run code snippet
Comment

filter object array

objects.filter((value, index, self) => {
  return self.findIndex(v => v.actor.name === value.actor.name) === index;
})
Comment

javascript filter array of objects

function isBigEnough(value) {
  return value >= 10
}

let filtered = [12, 5, 8, 130, 44].filter(isBigEnough)
// filtered is [12, 130, 44]
Comment

PREVIOUS NEXT
Code Example
Javascript :: clean way to Deal with undefined in chrome storage local get 
Javascript :: form serialize to json 
Javascript :: moment js date diff 
Javascript :: flatlist footer react native 
Javascript :: check if somethin exist in an object js 
Javascript :: javascript how to get every element after the 1st in an array 
Javascript :: Error: Could not symlink include/node/common.gypi /usr/local/include/node is not writable. 
Javascript :: css 2 components side by side react 
Javascript :: array traversal backward 
Javascript :: does json only support ascii 
Javascript :: javascript ascii to hex 
Javascript :: ERR_OSSL_EVP_UNSUPPORTED 
Javascript :: es6 foreach 
Javascript :: video play on page load 
Javascript :: getelementbytagname javascript 
Javascript :: javascript check if string ends with 
Javascript :: slice eliminar el ultimo caracter 
Javascript :: refresh div jquery 
Javascript :: get all input values by class jquery 
Javascript :: faker npm 
Javascript :: datatables column freeze 
Javascript :: jquery on checkbox checked es6 
Javascript :: javascript log error without traceback 
Javascript :: typeerror object(...) is not a function react useParams 
Javascript :: character to ascii in js 
Javascript :: event listener for element lost focus 
Javascript :: sending form data with fetch using js 
Javascript :: vue htmlWebpackPlugin.options.title 
Javascript :: javascript object syntax example with find 
Javascript :: random light color js 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =