+ 1
I need to create type of variable elem
Example (doesn't work): var elem = ['1','2']; var elem.type = ['first','second','third'];
2 Respuestas
+ 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);
+ 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