Good afternoon, I try to get an array through Api using Object.key (obj) .map, but I get only its number. Can anyone help what I am doing wrong?

My array:

enter image description here

My code: I check the array:

var nameObj = item.categories; Object.keys(nameObj).forEach(function(name) { console.log(name + ': ' + nameObj[name]); }); 

Trying to withdraw:

  let item = this.props.item; return ( <div className="back-info"> <p className='grey-text text-lighten-1'>Color:</p> {Object.keys(item.colors).map((id, name) => { return ( <a key={id} className='grey-text text-darken-4'>{name}</a> ) })} </div> ) 

Next output is this:

enter image description here Instead of the name number:

enter image description here

    1 answer 1

    Judging by the screenshot item.colors is an array, arrays are displayed as

     {item.colors.map((color) => { return ( <a key={color.id} className='grey-text text-darken-4'>{color.name}</a> ) })} 

    Or so, if your JSX preprocessor supports this syntax

     {item.colors.map(({id, name}) => { return ( <a key={id} className='grey-text text-darken-4'>{name}</a> ) })}