Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 12 hours ago.

Improve this question

I am trying to use array map function to display array elements in react native. but its getting error. please find the below format for object.

{"463291313313":{"name":"qfqwf","path":"/storage/emulated/0/Download/qfqwf.mp3"},"875412993776":{"name":"dwdd","path":"/storage/emulated/0/Download/dwdd.mp3"},"671139722412":{"name":"dwdfwff","path":"/storage/emulated/0/Download/dwdfwff.mp3"}}

and below are the code for the ui:

{Object.entries(jsonvalues).map((item,key)=>{

return(

{item}

)

})}

I need to extract each name and path from each array object. kindly help me out to solve the issue

# Answer 1

4d350fd91e33782268f371d7edaa8a76.png

item parameter is an array with each key and the value of the object.

[

"463291313313",

{

"name": "qfqwf",

"path": "/storage/emulated/0/Download/qfqwf.mp3"

}

]

You can destructure the value part to get the name and the path

Also, if you don't want the key, you can use 'Object.values'

const jsonvalues = {"463291313313":{"name":"qfqwf","path":"/storage/emulated/0/Download/qfqwf.mp3"},"875412993776":{"name":"dwdd","path":"/storage/emulated/0/Download/dwdd.mp3"},"671139722412":{"name":"dwdfwff","path":"/storage/emulated/0/Download/dwdfwff.mp3"}}

Object.entries(jsonvalues).map(([,{ name, path }]) => {

console.log(name, path)

})

Object.values(jsonvalues).map(({ name, path }) => {

console.log(name, path)

})

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐