Trying to convert an array of arrays (where the inner arrays only have two values stored) into an object.
This is what I've got so far:
function fromListToObject(array) {
var obj = {};
for (i in array) {
obj[array[i[0]]] = array[i[1]];
};
return obj
};
A1=[['make', 'Ford'], ['model', 'Mustang'], ['year', 1964]];
console.log(fromListToObject(A1));
But it's giving me an object where the keys are the array pairs, and the values are "undefined."
Halp?
for...inloops to iterate over an array, they're meant for objects. Use a normal for loop.for (i = 0; i < array.length; i++)- MDN web docs on this subject.