reference map value in the same map (JavaScript)

I am certain my issue here is not knowing what to call what I’m trying to do here, so any help with that would be appreciated, but I’d like to map over an array and create two values, where the first one refers to the prior value… is that possible?

arr =[1,2,3]
arr.map((el, i) => ({ 
   x: el, 
   y: 5, 
   z: y[i] + 2 // is there a way I can write this so I can refer to y ???
}))

any help appreciated!

Leave a Comment