Reputation: 17352
Assuming this is my array data
[
{ target: ['foo', 'bar'] },
{ target: [] }
]
I need to check if there is minimum of one item for any target array. So in the above example the result should be true
.
For this, the result is false
:
[
{ target: [] },
{ target: [] }
]
I'm not quite sure how to face this. So I think I have merge all target elements into one array and check if there is an empty array or not.
If this is the correct way, I just need a hint how to merge all arrays into one.
Upvotes: 1
Views: 49
Reputation: 386746
You could use Array#some
and check the length property of target
property.
var array = [{ target: ['foo', 'bar'] }, { target: [] }];
console.log(array.some(({ target }) => target.length));
Upvotes: 4