Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

find parent index of nested array object javascript

var arr = [{
  elements: [{
    id: '123',
    field: 'value'
  }, {
    id: '456',
    field: 'value'
  }]
}, {
  elements: [{
    id: '789',
    field: 'value'
  }]
}]

var i = arr.findIndex(function(o) {
  return o.elements.some(function(e) {
    return e.id == 456;
  })
})

console.log(i)
 Run code snippet
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #find #parent #index #nested #array #object #javascript
ADD COMMENT
Topic
Name
6+5 =