“Filter array objek dengan array objek” Kode Jawaban

cara memfilter array objek di 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

Cara memfilter daftar objek dengan array di 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)
Busy Bird

Filter array objek dengan array objek

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

Filter Array Objek Filter

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

Jawaban yang mirip dengan “Filter array objek dengan array objek”

Pertanyaan yang mirip dengan “Filter array objek dengan array objek”

Lebih banyak jawaban terkait untuk “Filter array objek dengan array objek” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya