0

I can display the twitter one but the person object i can't

enter image description here

I tried this:

comps=comps.map(function(comp,index){
return(
    <div key={index}>
Twitter : <a href={comp.twitter}>{comp.twitter}</a> // this one work
Person Name:<span className="PersonneName">{comp.person.nameP}</span> // not working
</div>
);
});

Thank you

1 Answer 1

1

person is an array, so you will likely want to .map() over it as well. Your code might look something like this.

comps=comps.map(function(comp,index){
return(
    <div key={index}>
Twitter : <a href={comp.twitter}>{comp.twitter}</a> // this one work
Person Name: {comp.person.map(val => {
  return <span className="PersonneName">{val.nomP}</span> 
})}
</div>
);
});

However, you're obviously going to return multiple people here. Depending on what you want to do, just handle the array appropriately.

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

5 Comments

i can do that for the jobP and depuis ? @Christopher Messer
On the array i Have 3 objects i want to display all of them
yes - val.jobP and val.depuis will work as you expect inside of the second .map()
that's not working the way i want,it diplay me all the name near each other. i want name + job + depuis name+job+depuis name+job+depuis sorry to bother you
comps=comps.map(function(comp,index){ return( <div key={index}> Twitter : <a href={comp.twitter}>{comp.twitter}</a> Person Name: {comp.person.map(val => { return <span className="PersonneName">{val.nomP} {val.jobP} {val.depuis} </span> })} </div> ); });

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.