-
Notifications
You must be signed in to change notification settings - Fork 0
getLastN(arrayObject,n,query)
Bhumil Sarvaiya edited this page Aug 31, 2017
·
1 revision
The function will return array of last n objects in array which satisfy the query passed.
If the number of objects in array satisfying the query is p which is less than n, then it will return array of last p objects in array that satisfy the query
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.getLastN(obj,2,{'type':'array'}))
//get last 2 objects with type: array
// Output: [ { name: 'xyz', type: 'array', age: 22 },
// { name: 'ghi', type: 'array', age: 20 } ]