Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript wrap object in array

const anObj = {name: "Hi"};
const anArr = [{name: "Hi"}];

const wrapped1 = [anObj].flat() 
const wrapped2 = [anArr].flat() 

console.log(wrapped1);  // wrapped1 is [{name: "Hi"}]
console.log(wrapped2);  // wrapped2 is [{name: "Hi"}]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #wrap #object #array
ADD COMMENT
Topic
Name
4+4 =