Determine the difference between values in an object and an array
P粉930534280
2023-09-03 19:28:50
<p>I have the following array of objects and numbers. How to tell which number in the array does not exist as an id in the object? In the example below, I want 1453. </p>
<pre class="brush:php;toolbar:false;">[
{id: 60, itemName: 'Main Location - 1100 Superior Road - Cleveland'}
{id: 1456, itemName: 'Third Location - 107,West 20th Street,Manhattan - New York'}
]
[60, 1453, 1456]</pre></p>
For more data items and more
itemid
, I would choose one to createSet
viamap
ping theid
...of each
itemListDirectly from a
Collection
orMap
instance is faster than e.g. byiterating over the array over and over again
orcontains
externalfiltering
tasks.Filtering unmatched item-
id
List is as simple as......Example code...
You can use
.map()
and then.filter()
and.includes ()