v2.5.2
Giriş yap

filter ile ilgili sorun için yardımcı olabilir misiniz?

tvarnext
238 defa görüntülendi

''''
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.

Cevap yaz
Cevaplar (2)
abdullahx
829 gün önce
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)
tvarnext
829 gün önce

önce markdown yazmayı öğrenmem gerek dimi ? :)