0

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.

2
  • yes it is. If you provide a dataset and code of what you have done. Commented Mar 25, 2020 at 21:07
  • 1
    Let your code breathe mate, you'll suffocate. What you're asking for are arrays of objects, which Javascript certainly supports. Any type can be in an array. Commented Mar 25, 2020 at 21:22

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.