I have a problem with my code as when I increase the number of elements inside the array it runs only the last added 3 elements only not the full list I don't know what's wrong in my code. please help!
var array = [
['make', 'Ford'],
['model', 'Mustang'],
['year', '1964'],
['make', 'Honda'],
['model', 'CRV'],
['year', '2000']
];
function fromListToObject(array) {
var obj = Object.create(null); // empty container for my object
for (var i = 0; i < array.length; i++) { //declare the 1st array loop
var arr1 = array[i]; //decleare the nested array
obj[arr1[0]] = arr1[1]; //1st item = 2nd item in the nested array
}
return obj;
}
var result = fromListToObject(array);
console.log(result);
obj[arr1[0]]always?. Isn't it about your loop step increment elementi?{make: ["Ford", "Mustang"], model: ["Mustang", "CRV"], year: ["1964", "2000"]}or[{ make: 'Ford', model: 'Mustang', year: '1964' }, { make: 'Honda', model: 'CRV', year: '2000' }]?