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"]];
asked Feb 3, 2013 at 13:11
jason
4,58923 gold badges104 silver badges157 bronze badges
2 Answers 2
You could use map():
var employees=["Adam","Barb","Chris"];
var newEmployees = employees.map( function( item ){ return [ item ]; } );
answered Feb 3, 2013 at 13:12
Sirko
74.4k19 gold badges157 silver badges194 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
Sirko
@HMR But a suitable shim is given on MDN as well. So just add the shim and you should be alright.
HMR
Yes, here is the map for browsers that don't implement it: developer.mozilla.org/en-US/docs/JavaScript/Reference/… Just needed mentioning if you need support for IE<9
Sirko
@HMR Did you notice, that this link is already part of my answer?
var employees = ["Adam", "Barb", "Chris"];
for (var i = employees.length; i--;) {
employees[i] = [employees[i]];
}
answered Feb 3, 2013 at 13:12
David G
97.6k41 gold badges173 silver badges258 bronze badges
Comments
lang-js