.push()

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

push(key, value)

Parameter

Description

key

Stringarrow-up-right

The key of the target array

value

JSONDataarrow-up-right

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