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:
- I have my array constructed like so:
const super_array = [];
JavaScript
x
6
1
super_array.push({
2
produs: rezultate[i].produs,
3
email: rezultate[i].email,
4
pretDorit: rezultate[i].pretDorit
5
});
6
Further down into the code, I want to assign new data to the array, like so :
JavaScript151for(let j=0; j<results.length; j++) {
2priceNumber = parseFloat(results[j].replace('<span>Lei</span>', '')) ;
3super_array.push({price: priceNumber})
4}
5
Result:
Right now, I get the following structure:
JavaScript
1
6
1
super_array({
2
produs: rezultate[i].produs,
3
email: rezultate[i].email,
4
pretDorit: rezultate[i].pretDorit
5
}, {pret: priceNumber});
6
What I would like to get is:
JavaScript
1
7
1
super_array({
2
produs: rezultate[i].produs,
3
email: rezultate[i].email,
4
pretDorit: rezultate[i].pretDorit,
5
pret: priceNumber
6
});
7
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