“Фильтруя массивы объектов” Ответ

Как отфильтровать массив объектов в 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}]
Handsome Hedgehog

JavaScript Filter Marray объектов

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" }]
Wicked Wryneck

JavaScript Filter Masse Of Objects Marray

var arr = [1,2,3,4],
    brr = [2,4],
    res = arr.filter(f => !brr.includes(f));
console.log(res);
Powerful Penguin

Фильтровая массива объектов с массивом объектов

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

Фильтруя массивы объектов

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

Ответы похожие на “Фильтруя массивы объектов”

Вопросы похожие на “Фильтруя массивы объектов”

Больше похожих ответов на “Фильтруя массивы объектов” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования