I am trying to access a property of an object which is within an object in an array. Quite the mouthful. The catch is that I want to do this using a variable. Its probably easier if i explain with code;
var array= [
{ id: 0, client: { id:0, clientName: "John" }},
{ id: 1, client: { id:1, clientName: "Tom" }}
]
console.log(array[0][client][clientName]); // Displays correctly
So the above code works as expected using the brackets notation. But as I said earlier I need to use a Variable like this example;
var array= [
{ id: 0, client: { id:0, clientName: "John" }},
{ id: 0, client: { id:0, clientName: "John" }}
]
var property = "client.clientName";
console.log(array[0][property]); // Does not work
I understand why this code wouldn't work but really this is more of a pseudo code to explain what I am trying to achieve!