I am having this array.
const array = ["Pizza","Pasta","Choco"];
I want to do this:
const array = [["Pizza"],["Pasta"],["Choco"]];
How can I do this?
Using Array.prototype.map(), you can provide a function (str => [str]) which wraps each of your string food elements in an array. This will give you a new array, which contains all your elements nested within their own arrays.
See example below:
const array = ["Pizza","Pasta","Choco"];
const result = array.map(str => [str]);
console.log(result);
.map()to map each element to an array