java script map,How to use array map function in java-script
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

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)
})
更多推荐


所有评论(0)