Skip to content

How can I map though this array? #418

Answered by amannn
francisceril asked this question in Q&A
Discussion options

You must be logged in to vote

The trick is to move the array to your React component:

{
  "stats": {
    "years-of-service": {
      "title": "Years of service",
      "value": "34"
    },
    "happy-clients": {
      "title": "Happy clients",
      "value": "1000"
    },
    "partners": {
      "title": "Products",
      "value": "10000"
    },
    "employees": {
      "title": "Employees",
      "value": "100"
    },
    "offices": {
      "title": "Offices",
      "value": "5"
    }
  }
}
[
  'years-of-service',
  'happy-clients',
  'partners',
  'employees',
  'offices'
].map((key) =>
  <p key={key}>{t(`stats.${key}.title`)} ({t(`stats.${key}.value`)})</p>
)

Hope this helps!

Replies: 5 comments 15 replies

Comment options

You must be logged in to vote
3 replies
@manu-kz
Comment options

@manu-kz
Comment options

@amannn
Comment options

Comment options

You must be logged in to vote
3 replies
@amannn
Comment options

Answer selected by francisceril
@GaziRiad
Comment options

@amannn
Comment options

Comment options

You must be logged in to vote
5 replies
@amannn
Comment options

@francisceril
Comment options

@amannn
Comment options

@francisceril
Comment options

@amannn
Comment options

Comment options

You must be logged in to vote
1 reply
@amannn
Comment options

Comment options

You must be logged in to vote
3 replies
@Deniffer
Comment options

@luobogor
Comment options

@mtlaso
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
9 participants