Consider the below object and I’m trying to console the below-mentioned output.
const jonas = {
firstName: 'Jonas',
lastName: 'Schmedtmann',
age: 2037 - 1991,
job: 'teacher',
friends: ['Micheal', 'Peter', 'Steven']
};
console.log(`${jonas.firstName} has ${jonas.friends.length} friends, and his best friend is ${jonas.friends[0]}.`);
Now, instead of hardcoding friends in the console, how do I access the key name "friends" from the object?
3
Answers
You can use Bracket Notation :
You can use the following element
that return an array of Keys of the object so you can take the value using
You could try a for loop:
or even try: