add elements to array javascript setstate hooks map code example Example: usestate array push setTheArray([...theArray, newElement]);