splice in react code example
Example 1: splice state react
const array = [...this.state.people];
array.splice(i, 1);
this.setState({people: array});
Example 2: splice state react
const array = [...this.state.people];
array.splice(i, 1);
this.setState({people: array});
Example 3: splice javascript
const months = ['Jan', 'March', 'April', 'June'];
months.splice(1, 0, 'Feb');
// inserts at index 1
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "June"]
months.splice(4, 1, 'May');
// replaces 1 element at index 4
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "May"]
months.splice(0, 1);
// removes 1 element at index 0
console.log(months);
// expected output: Array ["Feb", "March", "April", "May"]