Skip to content

indexAll(arrayObject,query)

Bhumil Sarvaiya edited this page Aug 25, 2017 · 2 revisions

The function will return an array of index of all objects in array which satisfy the query passed.

If no object satisfy the condition, blank array will be returned.

var daex = require('json-daex')
var obj = [
  {
    name: 'abc',
    type: 'array',
    age: 20
  },
  {
    name: 'pqr',
    type: 'string',
    age: 20
  },
  {
    name: 'xyz',
    type: 'array',
    age: 22
  },
  {
    name: 'ghi',
    type: 'array',
    age: 20
  },
  {
    name: 'mno',
    type: 'number',
    age: 20
  }
]

console.log(daex.indexAll(obj,{'type':'array'}))
//get index of all objects with type: array
// Output: [ 0, 2, 3 ]

console.log(daex.indexAll(obj,{'type':'array','age':20}))
//get index of all objects with type: array and age: 20
// Output: [ 0 , 3 ]