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"]];

2 Answers 2

4

You could use map():

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

var newEmployees = employees.map( function( item ){ return [ item ]; } );
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]];
}

Comments

Your Answer

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.