.push()

Pushes an element into an array based on the provided key.

push(key, value)

Parameter

Description

key

String

The key of the target array

value

JSONData

The value to push into the array

Returns

Description

The updated data from the provided key's root

db.get('people'); // ['Peter', 'Henry']

db.push('people', 'Catherine'); // ['Peter', 'Henry', 'Catherine']

Also allows the use of dot notation:

db.get('user'); // { id: 32171, items: ['sword'] }

db.push('user.items', 'axe'); // { id: 32171, items: ['sword', 'axe'] }

Last updated