Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change value in array with index in react native [duplicate]

I have an array in my state:

state = {
  some_array: [1,1,1,3,6,3,6,23], // sorry for the syntax it's changed
 }
 
 

Now I want to change value in that array that has index let's say 4, and in this case that would be number 6, or if I want to change index 1, that would be second number or array.
I know this is probabbly very simple but I'm just very confused.

If you need more info please comment.

Thanks!

like image 315
crodev Avatar asked Dec 24 '22 04:12

crodev


1 Answers

I think that you can to use next code:

const some_array = [...this.state.some_array]
some_array[indexHere] = yourValue
this.setState({some_array:some_array})

This example --- true way for FP in react.

like image 198
Petrashka Siarhei Avatar answered Dec 25 '22 22:12

Petrashka Siarhei