1

I have written a for/in loop which displays the properties for the object person here:

const composer = {
  name: 'Edward Ellington',
  nickname: 'Duke',
  genres: ['jazz', 'swing'],
  instrument: 'piano'
};

for (let prop in composer) {
  console.log(`${prop}: ${composer[prop]}`);
} 

My question is how do I now display the values of the object? I apologize if this has already been answered but I did not find this question in my search.

I have tried to add this below console.log: console.log(composer.values(object1)); But it tells me this is wrong. What am I missing?

2 Answers2

0

Can't see your code. I think what you are asking is can be achieved as follows:

for (let key in obj) {
  // value is accessed with this notation `obj[key]`
  console.log(obj[key]);
}
0

You want Object.values.

const composer = {
  name: 'Edward Ellington',
  nickname: 'Duke',
  genres: ['jazz', 'swing'],
  instrument: 'piano'
};
const values = Object.values(composer);
console.log(values);
Unmitigated
  • 76,500
  • 11
  • 62
  • 80