marsoon
marsoon

Reputation: 21

React how to use array

I'm making a Project for Cat lover but When I use a API, I got a Problem. I got below this data but I want a get createdDate data like this 05-04 I Tried like this nowaDays[0].createdDate.substr(5, 5)` but I got only 05-04"

This is what I want

0: {id: 244, createdDate: "05-04", weight: 4}
1: {id: 245, createdDate: "05-04", weight: 5}
2: {id: 246, createdDate: "05-04", weight: 6}
3: {id: 247, createdDate: "05-04", weight: 6}
4: {id: 248, createdDate: "05-04", weight: 7}
5: {id: 249, createdDate: "05-04", weight: 8}
6: {id: 250, createdDate: "05-04", weight: 9}

this is original API

This picture what i got

Upvotes: 0

Views: 42

Answers (1)

user3832673
user3832673

Reputation: 354

There's a couple ways you could approach this:

  1. If you only want to pass "05-04", that should be handled at the API level, not with React.
  2. What I'd recommend is that you accept the full date, but then format it to the user using moment.js or another Date library. Visit this site for how to do that.

Upvotes: 1

Related Questions