Skip to content
Advertisement

Push data into existing array using javascript

I am trying to find a way to build my custom array, but I am not able to do so.

What I have done so far:

  1. I have my array constructed like so:

const super_array = [];

JavaScript
  1. Further down into the code, I want to assign new data to the array, like so :

    JavaScript

    Result:

Right now, I get the following structure:

JavaScript

What I would like to get is:

JavaScript

I am not sure if I have explained it correctly. Basically I want to have the priceNumber uniquely match with the other data in the existing array, and not to be added as a separate index.

Advertisement

Answer

super_array[0].pret = priceNumber

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement