cancel
Showing results for 
Search instead for 
Did you mean: 

Check if the element in the array is empty or not

nikola_k_popovs
New Contributor

[
{
“test”: [
{
“group1”: “”,
“id”: 1
},
{
“group1”: “test”,
“id”: 2
}
]
}
]

How can i check if group1 is empty or not?

2 REPLIES 2

jcornelius
New Contributor III

@nikola.k.popovski you could use a Find() which would return all the objects with group1.length==0, then see how many there are or process then ie $test.Find(data->data.group1.length==0)

bojanvelevski
Valued Contributor

Hi @nikola.k.popovski,

Since you have multiple objects in the test array, you’ll need to check every object separately. Mapping an additional field or replacing the object with a value that states if the group1 is empty is the way to go.

$test.map(x=>x.extend({"groupLength":x.group1.length})