Deena P Deena P - 5 months ago 12
Javascript Question

convert an array of objects to a dataset that can be feed into a jquery datatable

I have an array like below one,

["abc", "xyz", "mno"]


now I want to convert it into an another array which has wrapped each element with a square bracket, like below one

["abc"], ["xyz"], ["mno"]


so I can use this dataset to create single column datatable.

Answer

var a = ["abc", "xyz", "mno"];
var aa = [];
for(i in a){
  aa.push([a[i]]);
}
console.log(aa);