score:1

Accepted answer

i'd advice against it, because such a one-liner makes the code quite unreadable, in my opinion.

anyway, here it is...

{array.map((v,i) => {
  <input onchange={
    (e)=>setarray(
      [...array.slice(0, i), e.target.value, ...array.slice(i+1)]
    )}
  />
})}

given the array [1,2,3,4,5] and i=2 you will have:

  • ...array.slice(0, i)[1,2]
  • e.target.value → the new value
  • ...array.slice(i+1)[4,5]

Related Query

More Query from same tag