Choose where you’d like to start

insert

Table of Contents

Overview

The insert function adds specified elements or key-value pairs to a collection.

Note: You cannot add key-value pairs into an index-value type collection or elements into a key-value type collection.

Syntax

To insert key-value pairs:

<collectionVariable>.insert(<key> : <value>);

(OR)

To insert elements:

<collectionVariable>.insert( <element> );

where,

ParameterData typeDescription
<collectionVariable>COLLECTION

The variable to which the key-value pairs or elements will be added.

If the variable contains key-value pairs, this function will only accept key-value pairs as arguments. If an element is specified, a runtime error will be encountered.

If the variable contains elements, this function will only accept elements as arguments. If a key-value pair is specified, a runtime error will be encountered.

<key>ALL DATA TYPES

The key which will be inserted.

If a duplicate key is specified, its new value will overwrite its existing value, and the new key-value pair will not get added.

<value>ALL DATA TYPES

The value which will be inserted.​

<element>ALL DATA TYPESThe element which will be inserted.

Examples

 products = collection("Creator", "CRM", "Campaigns");
 products.insert("Analytics"); // inserts "Analytics" to the existing collection
 productVersion = collection("Creator" : 5);
 productVersion.insert("CRM" : 5); // inserts the new key value pair to the existing collection

Get Started Now

Execute