# Array Primitive

**URL:** <https://community.glideapps.com/t/array-primitive/30012>\
**Category:** Ask for Help\
**Tags:** custom-code\
**Created:** [August 4, 2021, 11:15pm UTC](https://community.glideapps.com/t/array-primitive/30012 "2021-08-04T23:15:41Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 4, 2021, 11:15pm UTC](https://community.glideapps.com/t/array-primitive/30012/1 "2021-08-04T23:15:41Z")

</div>

@Mark  
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?

---

<div class="post-metadata">

**Author:** ![Mark](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mark/32/125_2.png) [@Mark](https://community.glideapps.com/u/Mark)\
**Post date:** [August 6, 2021, 12:09pm UTC](https://community.glideapps.com/t/array-primitive/30012/2 "2021-08-06T12:09:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 6, 2021, 12:34pm UTC](https://community.glideapps.com/t/array-primitive/30012/3 "2021-08-06T12:34:42Z")

</div>

@Mark  
Here is a small application (I hope quite simple 😜)

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

YC Array Number works but not YC Array Primitive

**YC Array Number**

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/e/d/ed230ca35e857d41259ec1cff66f3b12b5792896.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/f/af26178777e33dbba48477b72f8e7ceb65138a26.png)

> **[Rank-Number](https://replit.com/@ManuN2/Rank-Number#manifest.json)**
>
> Ranks an array of numbers ascending or descending!
> Robert Petitto

**YC Array Primitive**

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/4/b40d92e0b40ae8d67d816ecccd07d056c13056e8.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/0/b0db4c67b5658527c58b127746a53f3e7f4768e8.png)

> **[Rank-Number-Primitive](https://replit.com/@ManuN2/Rank-Number-Primitive#manifest.json)**
>
> Ranks an array of numbers ascending or descending!
> Robert Petitto

Application  
[https://go.glideapps.com/support/88a81bcb-7508-411c-b4f4-7534a0166d45](https://go.glideapps.com/support/88a81bcb-7508-411c-b4f4-7534a0166d45)

---

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 6, 2021, 12:42pm UTC](https://community.glideapps.com/t/array-primitive/30012/4 "2021-08-06T12:42:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SantiagoPerez](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/santiagoperez/32/16807_2.png) [@SantiagoPerez](https://community.glideapps.com/u/SantiagoPerez)\
**Post date:** [August 6, 2021, 12:43pm UTC](https://community.glideapps.com/t/array-primitive/30012/5 "2021-08-06T12:43:17Z")

</div>

Happy cake day @Manu.n

---

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 6, 2021, 12:44pm UTC](https://community.glideapps.com/t/array-primitive/30012/6 "2021-08-06T12:44:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Lucas\_Pires](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/lucas_pires/32/64863_2.png) [@Lucas\_Pires](https://community.glideapps.com/u/Lucas_Pires)\
**Post date:** [August 6, 2021, 1:07pm UTC](https://community.glideapps.com/t/array-primitive/30012/7 "2021-08-06T13:07:30Z")

</div>

Yes, we need this one 😅

---

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [August 6, 2021, 7:32pm UTC](https://community.glideapps.com/t/array-primitive/30012/8 "2021-08-06T19:32:49Z")

</div>

Hola @Manu.n … happy Glide-birthday!! 🤣

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:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/9/2/92ac8c5bfd6c87f60a7451b5573cf60bdce773fe.png)

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:

> lk\_Number=[1,2,3,33,22,11]

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

> 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! 🤨

> 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);

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/1/31649acfcf78bc65e0ec7375069af1b742859c07.png)

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!

---

<div class="post-metadata">

**Author:** ![Mark](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mark/32/125_2.png) [@Mark](https://community.glideapps.com/u/Mark)\
**Post date:** [August 6, 2021, 7:40pm UTC](https://community.glideapps.com/t/array-primitive/30012/9 "2021-08-06T19:40:21Z")

</div>

> [@gvalero](#):
>
> 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?

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

---

<div class="post-metadata">

**Author:** ![Jacktools\_Net](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jacktools_net/32/18500_2.png) [@Jacktools\_Net](https://community.glideapps.com/u/Jacktools_Net)\
**Post date:** [August 6, 2021, 7:57pm UTC](https://community.glideapps.com/t/array-primitive/30012/10 "2021-08-06T19:57:21Z")

</div>

You can convert strings to numbers with [parseInt() - JavaScript | MDN](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/parseInt)

And numbers to string with  
[https://www.w3schools.com/jsref/jsref\_tostring\_number.asp](https://www.w3schools.com/jsref/jsref_tostring_number.asp)

---

<div class="post-metadata">

**Author:** ![Mark](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mark/32/125_2.png) [@Mark](https://community.glideapps.com/u/Mark)\
**Post date:** [August 6, 2021, 8:05pm UTC](https://community.glideapps.com/t/array-primitive/30012/11 "2021-08-06T20:05:29Z")

</div>

> [@Manu.n](#):
>
> The same source for two identical scripts except the manifest is different
> 
> YC Array Number works but not YC Array Primitive

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.

---

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [August 6, 2021, 8:25pm UTC](https://community.glideapps.com/t/array-primitive/30012/12 "2021-08-06T20:25:17Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 6, 2021, 8:45pm UTC](https://community.glideapps.com/t/array-primitive/30012/13 "2021-08-06T20:45:02Z")

</div>

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 “,”

```auto

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

```

---

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 6, 2021, 11:45pm UTC](https://community.glideapps.com/t/array-primitive/30012/14 "2021-08-06T23:45:06Z")

</div>

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)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/b/6b478f4572e6a1935623fd44b4743bb2365cd436.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/3/13df050dc34762a2e693f1b910a04e7241b3711b.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/8/2/8226e2fb83fac7d97504d6ad53c4594057bf50c2.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/2/4/2455becf87fb87189f295dbf3361124f540c5184.png)

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