+ 1

I need to create type of variable elem

Example (doesn't work): var elem = ['1','2']; var elem.type = ['first','second','third'];

26th Dec 2018, 11:33 AM
Bogdan Şveţ
Bogdan Şveţ - avatar
2 odpowiedzi
+ 2
How about you make an object with fields value and type? var elem = { value: ['1', '2'], type: ['first', 'second', 'third'] } // ['1', '2'] console.log(elem.value); // ['first', 'second', 'third'] console.log(elem.type);
26th Dec 2018, 11:53 AM
TurtleShell
TurtleShell - avatar
+ 1
You could use JavaScript object literal. A JavaScript object literal is a comma-separated list of name-value pairs wrapped in curly braces. Object literals encapsulate data, enclosing it in a tidy package. Here an example: var elem = { number: ['1','2'], type: ['first','second','third'] } console.log(elem.number[0]); console.log(elem.type[0]); https://code.sololearn.com/WWSuV9CnRKWa/?ref=app
26th Dec 2018, 11:55 AM
Calviղ
Calviղ - avatar