Js array traversing objects

clipboard.png

I want to take the url in the object status = = "success" instead of the url of the object status = = "ready". It can"t be realized by using array forEach and filter.

May.07,2022

the phone really can't type the code literal description. Use filter

.

return item.status===sucess
and item.url

just OK


const result = arr.reduce(
  (total, cur) => (cur.status === 'success' ? [...total, cur.url] : [...total]),
  []
)

let urls = arr.filter (item= > item.status=== "success") .map (item= > item.url)


const arr = [{status:'success',url:'/a'},{status:'success',url:'/b'},{status:'ready',url:'/c'}];
const arr1 = arr.filter(v=>v.status!=='ready'); // [{status:'success',url:'/a'},{status:'success',url:'/b'}]
const arr2 = arr1.map(v=>v.url); // ['/a','/b']
Menu