简体   繁体   中英

how can I convert react-native data?

// i have to change my data to this form
items={{
'2021-04-20': [{name: 'item 1 - any js object'}],
'2012-04-21': [{name: 'item 2 - any js object'}]
}}

I am trying to show data below using react-native calendar library's agenda. And agenda needs the form of data like above.

['20210420': 'work', '20210421': 'sleep'] //the data i have

how can i convert my data by using react-native code?

Maybe this can help you!

 const data = {'20210420': 'work', '20210421': 'sleep'} const formattedData = {} Object.entries(data).forEach(([key, value]) => formattedData[`${key.substr(0, 4)}-${key.substr(4, 2)}-${key.substr(6)}`]= [{ name: value }]) console.log(formattedData)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM