Problem Pushing Object into Array

I am trying to append some data into an array that will be used to send a triggered email. All code working fine except the push().

let toInsert = {
      "Firstname": firstname,
      "Lastname": lastname,
      "Email": email,
      "Phone": phone
}

I want to add an additional line (“ParentName”: parent) to the toInsert array and have tried several ways using push(), but each time I get an error: “toInsert.push is not a function.”

Attempt 1:

toInsert.push({"ParentName" : parent});

Attempt 2:

let obj = {}
obj["ParentName"] = parent;
toInsert.push(obj);

Attempt 3:

let obj=
    {"ParentName": parent}  
    toInsert.push(obj);

Running out of ideas on how to do this. :crazy_face:

Read a bit about objects and arrays, you’re not trying to insert an object to an array, you have initialized an object and are trying to put another object into it, no array in sight

1 Like

Delete this. Try again.

Yes, it is indeed an object not an array or object array, so push() won’t work. Managed to figure it out eventually.

toInsert["ParentName"] = parent;
1 Like