Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

add object to array javascript

let obj = { name: 'Bob' };
let arr = [{ name: 'John' }];

// add obj to array
arr = [...arr, obj];

console.log(arr) // [{ name: 'Bob' }, { name: 'John' }];
 
PREVIOUS NEXT
Tagged: #add #object #array #javascript
ADD COMMENT
Topic
Name
6+1 =