Home > Software design >  How do I show a of list elements of an array?
How do I show a of list elements of an array?

Time:05-24

I have a large array of 465 items, with each item having five elements. E.g.

const fixture = {id: '955dc591ce70', title: 'Liverpool vs Arsenal', date: '2022-03-18', start: '2022-03-18T19:35:00', end: '2022-03-18T21:05:00', competition: 'Premier League'}

I want to ouput an array of just the competitions for each game. I have tried console.log(this.state.fixtures.competition) but no success. How can i acheiev this?

CodePudding user response:

Try this outputting to console

this.state.fixtures.forEach(fixture => console.log(fixture.competition));

CodePudding user response:

You can use map function to achieve this:

{
    this.state.fixtures.map(item => <p key={item.id}>{item.competition}</p>)
}
  • Related