filter ile ilgili sorun için yardımcı olabilir misiniz?
''''
let group = 1
let y = [
{
name: "John",
groupId: [1, 2]
},
{
name: "Doe",
groupId: [1]
},
{
name: "Sam",
groupId: [1, 3]
},
{
name: "Joe",
groupId: [3]
}
]
this.y.filter(f => f.groupId === group)
''''
// array içinde object içindeki arrayin içindeki sayı ile eşleşen object'leri filtrelemek istiyorum.
Soru hatalı mı? 👎
Eğer sorunun kurallara aykırı olduğunu düşünüyorsanız lütfen bize bildirin!
Cevaplar (2)
let group = 1,
y = [
{
name: "John",
groupId: [1, 2]
},
{
name: "Doe",
groupId: [1]
},
{
name: "Sam",
groupId: [1, 3]
},
{
name: "Joe",
groupId: [3]
}
]
let a = y.filter(f => f.groupId.includes(group))
console.log(a)
// (3) [{…}, {…}, {…}]
// 0: {name: 'John', groupId: Array(2)}
// 1: {name: 'Doe', groupId: Array(1)}
// 2: {name: 'Sam', groupId: Array(2)}
// length: 3
// [[Prototype]]: Array(0)