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

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

filter object js

const raw = {
  item1: { key: 'sdfd', value:'sdfd' },
  item2: { key: 'sdfd', value:'sdfd' },
  item3: { key: 'sdfd', value:'sdfd' }
};

const allowed = ['item1', 'item3'];

const object = Object.fromEntries(
	Object.entries(tt).filter(([key, value]) => currentInputs.includes(key))
);
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 :: javascript foreach loop array 
Javascript :: How can i change Header Bar height in react native 
Javascript :: why bigint js 
Javascript :: discord js embed footer 
Javascript :: npm md to html 
Javascript :: create a react app 
Javascript :: remove last character of string in javascript 
Javascript :: Math max with array js 
Javascript :: how to count duplicates in an array javascript 
Javascript :: v-bind shorthand 
Javascript :: bind in javascript 
Javascript :: xml vs json 
Javascript :: stykesheet create 
Javascript :: toggle button in angularjs bootstrap 
Javascript :: foreach in the elements with a data attibute jquery 
Javascript :: how to pass an image path to img src in Reactjs 
Javascript :: javascript async await not waiting 
Javascript :: append item in treeview vuetify 
Javascript :: react router dom default params 
Javascript :: 8ball javascript 
Javascript :: window onfocus 
Javascript :: change profile photo with javascript 
Javascript :: jquery embeded by console 
Javascript :: js intellisence not working 
Javascript :: crud in node 
Javascript :: how to fill html datalist with array values in javascript 
Javascript :: jquery default value 
Javascript :: duplicate characters in a string javascript 
Javascript :: intellij debugger export object as json 
Javascript :: define dynamic initial values for Formik in React 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =