V
V
Vadim Stepanenko2018-03-21 13:36:14
JavaScript
Vadim Stepanenko, 2018-03-21 13:36:14

How to create a two dimensional js array?

Hello! How to create a two dimensional array in js?
Tried to do like this:

var modelInfo['title']['color'] = 'qq';
console.log(var modelInfo['title']['color']);

, but gives an error
Uncaught SyntaxError: Unexpected token [
The essence is as follows: initially, the script contains data about the product, for example
var modelInfo['1']['color'] = 'blue';
var modelInfo['1']['inch'] = '72';
var modelInfo['1']['price'] = '1500';

var modelInfo['2']['color'] = 'red';
var modelInfo['2']['inch'] = '35';
var modelInfo['2']['price'] = '800';

and depending on the selected item in the selectbox, the specified information will be displayed. I made a conclusion depending on the selected item, but I got stuck with arrays

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mShpakov, 2018-03-21
@Vadim1899

{
  "1": {
    "color": 1,
    "title": "asd"
  },
  "2": {
    "color": 1,
    "title": "asd"
  }
}

How about this?

M
M-ka, 2018-03-21
@M-ka

open any js tutorial and read the relevant section.... there will even be examples

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question