Array Primitive

it seems that according to my little tests, that a Primitive Array is necessarily of type String even if the source is number.
Which forces you to do 2 scripts for the same function (1 for string, 2 for number)

is there a solution?

Could you make a simple example app that shows the problem, please?

Here is a small application (I hope quite simple :stuck_out_tongue_winking_eye:)

The same source for two identical scripts except the manifest is different

YC Array Number works but not YC Array Primitive

YC Array Number

YC Array Primitive


1 Like

The idea is to be able to use the same script for a “number” or “text” value.

1 Like

Happy cake day @Manu.n

Yes thank you but I must share the cake with this community


Yes, we need this one :sweat_smile:

Hola @Manu.n … happy Glide-birthday!! :rofl:

I think the problem begins when a Glide’s array is created. For an unknown reason, all elements/values are converted to string and it is not fine, the array should keep the original format of all values.

Testing, I have this:

a) My lk_Number column is an array and saves all values belonging to my Number column which has a number format.
In other words, my lk_Number array must be:


but instead, Glide creates a new array with a string format and any code gets complicated accidentally :upside_down_face::

lk_Number=[“1”, “2”, “3”, “33”,“22”, “11”]

and this is the reason why my code faults using the .Sort() method without parameter. It is sorting numbers saved as text/string instead of real numbers! :face_with_raised_eyebrow:

sorted = p8.sort();

The .Sort() method can work without problems and sort any array with numbers, texts, alphanumerical or boolean but, but… but its exception is when numbers are saved/treated as text in an array, our case!.

With this issue, we always have to use .Sort() method with parameter to get a right result

sorted = p8.sort((a, b) => a - b);

Now my big doubt is: @Mark … my friend: is there any way to fix that unusual conversion from Number to String when an Array column is created?

Or at least, a quick/simple JS command to revert that Number/String conversion could be useful and fix this issue. I have other 2-3 YC scripts associated to sorting Arrays and sometimes they have a weird behavior and I think now, I know the cause.

Thanks, saludos!

Could you make a simple example app that shows the problem, please?

You can convert strings to numbers with parseInt() - JavaScript | MDN

And numbers to string with

1 Like

I see. Maybe Glide should ensure that number inputs are actually always represented as numbers, even if the declared type is primitive. I’ll put it on the wish list. For the time being you can/should try parsing the inputs as numbers if you really need to be able to operate on numbers and strings.

Thanks @Jacktools_Net

I was looking for something able to convert a whole array directly to Number without checking each position and convert it to Number but anyway, I will try it as a workaround.

Thanks anyway!

Yes converting to number is not necessarily the problem, but it is to detect if the values ​​are all numbers or strings
With the problematic of the decimal separator according to the regions “.” or “,”

  // convertion string to number
  array = (item) {
    item = item.replace(",",".");
    return parseFloat(item);

Okay, I did that.

Number / Text compatible.

The type of the array is determined by the type of the RankItem parameter

It’s not really elegant but obviously it works. (finally to be tested thoroughly)

I’m not sure this is a good solution, especially if you’re only using numbers for example.
But it exists

1 Like