Skip to main content

how can I filter array in object?

I would like to filter only people who have the color red as favColor... how can I do that? this is what i tried: but not worked

const filteredpersonen = personen.filter(personen => personen.favColor= 'red');
console.log(filteredpersonen);

This is my code:

let personen = [
    {
      naam : 'jan',
      age : 41,
      favColor:[
        'blue',
        'green',
        'yellow',
        'orange'
      ]
    },
    {
      naam : 'james',
      age : 31,
      favColor:[
        'red',
        'black',
        'yellow',
        'purple'
      ]
    },
    {
      naam : 'linda',
      age : 21,
      favColor:[
        'blue',
        'white',
        'red',
        'grey'
      ]
    },
    {
      naam : 'marya',
      age : 31,
      favColor:[
        'creme',
        'green',
        'orange',
        'red'
      ]
    }
  ]
Via Active questions tagged javascript - Stack Overflow https://ift.tt/wbkqJ68

Comments