0

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

2 Answers 2

4

You could use map():

var employees=["Adam","Barb","Chris"];
var newEmployees = employees.map( function( item ){ return [ item ]; } );
answered Feb 3, 2013 at 13:12
Sign up to request clarification or add additional context in comments.

3 Comments

@HMR But a suitable shim is given on MDN as well. So just add the shim and you should be alright.
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
@HMR Did you notice, that this link is already part of my answer?
2
var employees = ["Adam", "Barb", "Chris"];
for (var i = employees.length; i--;) {
 employees[i] = [employees[i]];
}
answered Feb 3, 2013 at 13:12

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.