Am attempting to output a value from an array, but get the error: array1 is not defined no-undef
Code Snippet:
constructor() {
super();
this.state = {
array1: [],
}
}
//code snippet componentDidMount:
componentDidMount(props) {
this.setState({array1: [5, 12, 8, 130, 44] })
}
//code snippet, function:
found = this.state.array1.find((element) => {
return element > 10;
});
code snippet:
render(){
console.log(found);
}
the page errors out in the arrow function, Could I get some help please?
Your constructor should be changed to
You haven't defined your
array1
as a state.Update (Updated answer based on comments)