How to filter an array with objects?
-
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 youJavaScript Anonymous, Jun 22, 2019 -
numbers.filter(n => !objects.some(m => m.number === n))
Anonymous -
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
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!