Lodash where method for considering nested array elements

lodash, where the method does not consider nested array elements when searching. Consider the example below:

var foo = [
  {
    "id": "123",
    "elements": [
      {
        "id": "1231",
        "name": "foo1"
      },
      {
        "id": "1232",
        "name": "bar1"
      }
    ]
  },
  {
    "id": "456",
    "items": [
      {
        "id": "4561",
        "name": "foo2"
      },
      {
        "id": "4562",
        "name": "bar2"
      }
    ]
  }
]

_.where(foo, { 'id' : '123' } ) //works and returns the element
_.where(foo, { 'id' : '1231' } ) //fails.. trying to match the first element in the elements array. does not return matched element

      

Is there an API in lodash or another JavaScript library for deep search?

+3


source to share





All Articles