Skip to content

How to change a Item value of a state. #14156

@Symous

Description

@Symous

for example, I have a list state like this:

this.state = {
    list:[1,2,3,4,5]
}

How can I change the value of the first item of list from 1 to 0?

I usually use like this but I don't believe that is the best way.

var temp = this.state.list;
temp[0] = 0;
this.setState({ list : temp});

Please who can tell me is there any better way to do this ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions