0

Assuming I have the following javascript array:

[["0", Object { name="john"}], ["1", Object { surname="white"}]];

How can i print the variable name "name" (not "john", which is its value)

console.log(result[0][1] ?????);

1 Answer 1

2

data[0][1] returns {name: "john"}. You can then use the Object.keys function that will return the keys of an object. It will return ['name']. Then you just have to get the first item of this array.

const data = [["0", {name: "john"}], ["1", {surname: "white"}]];

console.log(Object.keys(data[0][1])[0]);
console.log(Object.keys(data[1][1])[0]);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.