I am trying to access name of the array inside of other array in the loop but i am failing. I am able to access name of that array if it's not inside another array by fx. Object.keys({thisObject})[0] but when it's inside of another array it does not work.
I have already tried for each loops, for loops. Nesting initialized arrays in the new array:
var arr1 = [1,2,3]
var arr2 = [4,5,6]
var arr3 = new Array(arr1,arr2)
Still, in the loop i cannot get the name of the arr1 and arr2. I have possibility to access their values but not the names..
var cars = new Array("Porshe","Mercedes");
var bikes = new Array("Yamaha","Mitsubishi");
var vehicles = new Array(cars, bikes);
for (var key in vehicles) {
var value = vehicles[key];// This is retruning whole array, not the name
console.log(Object.keys({vehicles[key]})[0]) // That does not work
vehicles[key].forEach(car => {
console.log(car)
});
}
//or
for (let i=0;i<vehicles.length;i++){
console.log(vehicles[i]); //This is also returning whole array - same method.
for(let j = 0; j< vehicles[i].car.length;j++){
console.log(vehicles[i][j]);
}
}
The result which i want to get is to listing the cars in the table where Cars are the headline and underneath are the Porsche, Mitsubishi and then Bikes are the next one.
var vehicles={cars: ["Porshe","Mercedes"], bikes: ["Yamaha","Mitsubishi"]}var vehicles={cars: ["Porshe","Mercedes"], bikes: ["Yamaha","Mitsubishi"]} for( var vehicle in vehicles){ console.log(vehicle) //That is working fine now for( var mark in vehicle){ console.log(mark) //That's returning lenght of the name of the array like 0,1,2,3,4,5 for Porshe } }vehicles["cars"].forEach(item => console.log(item))in place of "cars" you can place your variable.