append object to array javascript react hooks code example Example: usestate array push setTheArray([...theArray, newElement]);