简体   繁体   中英

How to create multidimensional associative array in javascript

Hy guys,

I am studying javascript.

Is it possible to create this type of array? where product code is replaced by values in particolar my variables cod_prodotto and not in a string like this.

var prezzo = $("input[name='prezzo']").map(function(){return $
(this).val();}).get();
var quantita_magazzino = $
("input[name='quantita_magazzino']").map(function(){return $
(this).val();}).get();
var cod_prodotto = $
("input[name='cod_prodotto_tmp']").map(function(){return $
(this).val();}).get();
  var myArray = new Array();
for (i=0; i<cod_prodotto.length; i++){
myArray[i] = {codice_prodotto:{'cod_prod': cod_prodotto[i], 
'prezzo': prezzo[i], 'quantita': quantita_magazzino[i]}};
}

[{codice_prodotto: {cod_prod: "S10_1949", prezzo: "98", quantita: "7276"}}, {codice_prodotto: {cod_prod: "S10_4757", prezzo: "85.68", quantita: "7302"}}, {codice_prodotto: {cod_prod: "S10_4962", prezzo: "103.42", quantita: "7302"}}] (3) (employer_page.php, line 261)

I would like to understand how to get for example the 98 values'.

Thanks all.

You can access the array element by its index, and the object value by its name. So you can access "98" value with this code :

arr[0].codice_prodotto.prezzo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM