Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I convert this object into an Array using GAS?

I got this showing as an object:
38,44,46
…while and it should be:
["38","44","46"]

I’d like to convert it to an Array, so that I can iterate over it.
I’ve tried doing so using this, but it’s still an object, as I get its type:
let tamanhosEsc = Object.values(values[29]);

This is how values is created:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const rngList = cadSheet.getRangeList(dataRng).getRanges();

  let values = new Array();

  for(let i = 0; i < rngList.length; i++) {
    let data = rngList[i].getValue();
    values.push([data]);
  }

I’ve tried creating it by specifying it as an Array, but still…

>Solution :

Play with the code above to understand the basic concept:

var obj = {"1":5,"2":7,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0}
var result = Object.keys(obj).map((key) => [Number(key), obj[key]]);

console.log(result);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading