-
Notifications
You must be signed in to change notification settings - Fork 0
updateFirstN(arrayObject,newValues,n,query)
Bhumil Sarvaiya edited this page Aug 31, 2017
·
1 revision
//common data
var daex = require('./index')
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
}
]
//e.g. 1
daex.updateFirstN(obj,{'age':12},2)
console.log(obj)
//Output
//[ { name: 'abc', type: 'array', age: 12 },
// { name: 'pqr', type: 'string', age: 12 },
// { name: 'xyz', type: 'array', age: 22 },
// { name: 'ghi', type: 'array', age: 20 },
// { name: 'mno', type: 'number', age: 20 } ]
//e.g. 2
daex.updateFirstN(obj,{'age':12},2,{'type':'array'})
console.log(obj)
//Output
//[ { name: 'abc', type: 'array', age: 12 },
// { name: 'pqr', type: 'string', age: 20 },
// { name: 'xyz', type: 'array', age: 12 },
// { name: 'ghi', type: 'array', age: 20 },
// { name: 'mno', type: 'number', age: 20 } ]
//e.g. 3
daex.updateFirstN(obj,{'newField':123},2)
console.log(obj)
//Output
//[ { name: 'abc', type: 'array', age: 20, newField: 123 },
// { name: 'pqr', type: 'string', age: 20, newField: 123 },
// { name: 'xyz', type: 'array', age: 22 },
// { name: 'ghi', type: 'array', age: 20 },
// { name: 'mno', type: 'number', age: 20 } ]