0

I have an array which stores data according to date, how can I render the data on a particular date?

I tried to use array[0].Data and it works, but what I really want to achieve is something like passing a prop "array(Jul)" and it shows the data in Jul. Is there a way to achieve this?

let array = [{Month: "Jul", Data: "this is my data", Place: "UK"},{Month: "Aug", Data: "this is my data2", Place: "USA"}] 

<View >
    <Text small bold white> {array(Jul).Data} </Text>
</View>

2 Answers 2

1

You can use find:

array.find(x => x.Month === 'Jul').Data
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very simple and easy !!
1

You could convert the array to an object

let array = [{Month: "Jul", Data: "this is my data", Place: "UK"},{Month: "Aug", Data: "this is my data2", Place: "USA"}] 

const newData = array.reduce((acc, item) => (acc[item.Month] = item.Data, acc),{});

console.log(newData)
console.log(newData['Jul'])

and accress to Data like below

<View >
    <Text small bold white> {newData['Jul']} </Text>
</View>

1 Comment

Thank you !! That gives me a new idea !!

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.