Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Push object to of the array Hooks


const [array,setArray] = useState([]);
Push value at the end:

setArray(oldArray => [...oldArray,newValue] );
Push value at the start:

setArray(oldArray => [newValue,...oldArray] );
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Push #object #array #Hooks
ADD COMMENT
Topic
Name
7+5 =