I need to match the name of the array with the name of a nesting array inside. Y
has many, many nesting arrays. I gave two as an example. Also, i
always has a random nesting array name. In this example, i
is equal to car
.
var y = {car:['honda','ford'],color:['red','green']/*,...More here*/};
i = 'car'; //This value can change to either 'car', or 'color', etc...
var x = y + i;
console.log(x);
I need to get the value of x
to become y.car
, which will log ["honda", "ford"]
. Instead, x
logs [object Object]car
. How do I get x
, var x = y + i
, to return ["honda", "ford"]
instead?
EDIT:
Yes, but x = y[i]
is not working in my for loop.
for (i = 0; y.length > i; i++) { console.log(y[i]); }