2

I am having a list like:

var a=[   
  {col1:"a", list:[{subCol:"s1"},{subCol:"s2"}]},   
  {col1:"b", list:[{subCol:"s1"},{subCol:"s2"}]}
]

Here am having list inside list. For this I want a query like enter code here

linq(a).where("$.col1=='a' && $.list.subCol=='s1'")

I tried this syntax but gives empty list as output. Is this correct?

Jaap
  • 81,064
  • 34
  • 182
  • 193

1 Answers1

1

list is an array of objects. I suppose you're trying to check if any item in the list has a subCol s1. You'd have to check the items.

var query = Enumerable.From(a)
    .Where("$.col1 === 'a'")
    .Where("Enumerable.From($.list).Any(\"$.subCol === 's1'\")")
    .ToArray();
Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272