Skip to content

Insert After

Description

This operation inserts a new value after an existing value in a list.

Method

Backendless.Hive(hiveName).ListStore(keyName).insertAfter(valueToInsert, anchorValue): Promise<number>;

where:

Argument                Description
hiveName Name of a hive where the operation is performed. String value.
keyName List name to add a new value. String value.
valueToInsert New value to add to the list. Can be of any JavaScript data type.
anchorValue Value which is used as a position anchor. Must be a value that is already present in the list.

Return Value

The number of values in the list after the insertion operation is complete.

Example

The example below inserts the value 'Grapes' after the 'Oranges' value in the 'fruits' list.

await Backendless.Hive('demoHive').ListStore('fruits').insertAfter('Grapes', 'Oranges')

where:

Argument                Description
'demoHive' Name of a hive where the operation is performed.
'fruits' Key name identifying a list where a new value is inserted.


Codeless Reference

list_api_insert_after

where:

Argument                Description
hive name Name of a hive where the operation is performed.
key name Key name identifying a list.
item New item that must be added to the list.
after item Value which is used as a position anchor. Must be a value that already exists in the list. The new value is insert after this one.

Returns the number of values in the list after the insertion operation is complete.

Consider the following List storage:

sample-list-after-insert

The example below inserts a new item "Dave" after the selected anchor value "Charlie":
after-insert-codeless