How to split this complex string into 3 columns an

2019-08-23 09:55发布

i've searched for some time but did not quite find what i need.

I've got this string:

["384.23","0.01",1],["383.9","16.15406671",2],["383.26","8.62406671",1],
["383.25","0.01",1],["383.22","6.57026928",1],["383.21","0.20029",1],....

It has 50 of these triplets, each within brackets.

I would like to split this data into 3 columns and 50 rows. For example the first row would contain 384.23 in col1, then 0.01 in col2 and 1 in column 3. Then on next row i would find the next triplet, and onto 50 rows like this.

I've tried to put this into an array, but i'm just going nowhere. Here's my code so far:

var array2 = [{}];

array2 = rawbids.split("],[");

//copy each element of array2 in a column
rgMyRange = first.getRange("B10:B59");

rgMyRange.setValue([array2])

but i only get this value in first column repeated on next 50 rows: ["384.23","0.01",1

and my code above would not even split the triplets yet....

thanks a lot

1条回答
时光不老,我们不散
2楼-- · 2019-08-23 10:28

ok it's working now, thanks to the guys above:

  var array2 = JSON.parse('[' + rawbids + ']')

  //copy each element of array2 in 3 columns and rows
  rgMyRange = first.getRange("B10:D59");

  rgMyRange.setValues(array2)
查看更多
登录 后发表回答