I am unable to read the property of array of objects from some other array. The property name of first array is the value from the second array. A bit complex to understand, but example would probably make it easier.
Consider below example having 2 arrays.
//Array 1
var arr1 = [
{Name: "Suyog",Nickname: "Su", ID : "123"},
{Name: "Santosh", Nickname: "Sandy", ID : "456"}
];
//Array 2
var arr2 = ["Name","ID"];
Now, I want to read value of the property 'ID' of 1st record in arr1. But, the property ID should be fetched from arr2
Also, checked link1 & link2, but didn't get much help.
This is what I have tried so far...
//Array 1
var arr1 = [
{Name: "Suyog",Nickname: "Su", ID : "123"},
{Name: "Santosh", Nickname: "Sandy", ID : "456"}
];
//Array 2
var arr2 = ["Name","ID"];
console.log("Expected Output: 123");
console.log(arr1[0].arr2[1]); //It gives error