Using App Scripts I've pulled all the headers in an array, strip out the text part and built an array of the below format:
[1,10,23,45,7,12,76,88,9]
Sample code:
var shHeader = sh.getRange(1, 3, 1, 20);
var shH1 = shHeader.getValues();
shH1 = shH1[0].sort();
When I do the normal sort() on the array, the order I'm getting is like:
[1,10,12,23,45,7,76,88,9]
I want sort to give me an output:
[1,7,9,10,12,23,45,76,88]
Can anyone help with any function or some easy hack to get my desired results?
You can pass a function into the sort method that takes two parameters.
shH1 = shH1[0].sort(function(a, b) {return a - b;});
Here is documentation to help you: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With