reactjs - JavaScript Map Function with React.js gives me index, but not value in the index -
so have in react file, works fine:
{this.props.profile.first_name}
the above code output actual value in there: "john doe" example.
but, when try , loop through each 1 check see if profiles empty (if user never inputted first name example), can't content display. undefined or indexes. below code doesnt' me.
var props = object.keys(this.props.profile).map(function(key, index, value) { console.log(key); ### gives me index console.log(index); ### undefined console.log(key[value]); ### gives me data, label name, not value console.log(index[value]); ##undefined if ([key[value]) { return ( <li classname="list-group-item"> <label>{key}</label>{[value]} </li> ); } })
how grab actual data value in there, this"{this.props.profile.first_name} key or value checks agains actual content in there (i.e. "john doe") , not index or undefined?
object.keys
returns
array object
keys, example have
this.props.profile = { first_name: 'name' };
object.keys(this.props.profile)
returns ['first_name']
, in order value in map should
object.keys(this.props.profile).map(function (key) { console.log(this.props.profile[key]); }, this);
Comments
Post a Comment