I have an array which includes some keys and subkeys of the object:
let keysArray = ['Computer Technics', 'Laptops', 'Lenovo', 'Ideapads',];
And also I have an object:
let obj = {
'Computer Technics': {
'Laptops': {
'Lenovo': {
'Ideapads': "data"
}
}
}
};
I need to get a link to the "data":
obj['Computer Technics']['Laptops']['Lenovo']['Ideapads']
I can't understand how to do that..
I mean I wrote a function which creates a link itself, but I have no idea how to connect it with obj
console.log(obj[getKey(keysArray)]); // obviously undefined as a result is put into '[]'
console.log(obj+getKey(keysArray)); //obviously it doesn't work too
function getKey(arr) {
let res = '';
for (i = 0; i < arr.length; i++) {
res = res + '[\'' + arr[i] + '\']';
}
return res;
}
Any help will be appreciated a lot! Thanks!