Skip to content

getLast(arrayObject,query)

Bhumil Sarvaiya edited this page Aug 25, 2017 · 1 revision

The function will return last object in array which satisfy the query passed.

If no object satisfy the condition, null 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.getLast(obj,{'type':'array'}))
//get last object with type: array
// Output: { name: 'ghi', type: 'array', age: 20 }