简体   繁体   中英

javascript array to multidimensional array

I have a question that follows this thread. Its a follow up to this answer.

Google Apps Script Spreadsheets - Write Array to cells

how do i get

var employees=["Adam","Barb","Chris"];

to look like this?

var employees=[["Adam"],["Barb"],["Chris"]];

You could use map() :

var employees=["Adam","Barb","Chris"];

var newEmployees = employees.map( function( item ){ return [ item ]; } );
var employees = ["Adam", "Barb", "Chris"];

for (var i = employees.length; i--;) {
    employees[i] = [employees[i]];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM