How to filter an array with objects?

  • 0
    There is an array like
    ['1', `2`,` 3`, `4`,` 5`]
    And there is also an array with objects of this kind.
    [
     {
        number: '3',
        name: 'Vasja',
     },
     {
        number: '5',
        name: 'Igor',
     }
    ]


    We need to end up with an array like this
    ['1', `2`,` 4`]

    That is, an array with all the numbers with which there are no objects. Thank you
    JavaScript Anonymous, Jun 22, 2019

  • 2 Answers
  • 0
    numbers.filter(n => !objects.some(m => m.number === n))
    Anonymous

  • 0
    1. Reduce a multidimensional array to a one-dimensional one

    2. Filter out the first, checking for values ​​in the second.



    let arr2_plain = arr2.map(item => item.number);
    let result = arr1.filter(item => !arr2_plain.includes(item));
    Evan May

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!