# Javascript not running

**URL:** https://community.glideapps.com/t/javascript-not-running/71518
**Category:** Ask for Help
**Created:** [March 8, 2024, 1:13pm UTC](https://community.glideapps.com/t/javascript-not-running/71518 "2024-03-08T13:13:57Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![heidikruger](https://avatars.discourse-cdn.com/v4/letter/h/c37758/32.png) [@heidikruger](https://community.glideapps.com/u/heidikruger)
#### Post date: [March 8, 2024, 1:13pm UTC](https://community.glideapps.com/t/javascript-not-running/71518/1 "2024-03-08T13:13:57Z")

</div>

I am rather new to Javascript. I am trying to run following code which I googled so that could be problem #1. The code is suppose to read a list which is created in one of my columns and to extract unique values only.  
It does not return any results. Can any one please tell me what I am doing wrong?

```auto
let arr = [p1];
let unique = [];
arr.forEach(function (element) {
    if (!unique.includes(element)) {
        unique.push(element);
    }
});
return unique;

```

Screenshot of my setup:  
 ![Screenshot 2024-03-08 at 15.09.10](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/0/00965809cfaedf68e80a08548a3257edf030051b.png)

---

<div class="post-metadata">

### Author: ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)
#### Post date: [March 8, 2024, 1:17pm UTC](https://community.glideapps.com/t/javascript-not-running/71518/2 "2024-03-08T13:17:09Z")

</div>

The javascript column doesn’t return arrays. You need to first convert the array into a string. Once you return a text string, then you can convert it to an array using a Split Text column.

> [@Javascript column help: Recurring classes](https://community.glideapps.com/t/javascript-column-help-recurring-classes/71334/4):
>
> OK, you still need a return on ‘output’, but you don’t even need to define an output variable. Just do a return on the function call. You still need to convert your array to a string. Replace this: return schedule; With this return schedule.join(',');

---

<div class="post-metadata">

### Author: ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)
#### Post date: [March 8, 2024, 1:20pm UTC](https://community.glideapps.com/t/javascript-not-running/71518/3 "2024-03-08T13:20:41Z")

</div>

Also, are you trying to pass an array or text into the p1 parameter? If it’s an array, you may need to first convert it to a comma delimited string using a Joined List column, and then perform a Split in the javascript code to split it into an array.

The javascript column is only really good at passing text strings in and out.

---

<div class="post-metadata">

### Author: ![heidikruger](https://avatars.discourse-cdn.com/v4/letter/h/c37758/32.png) [@heidikruger](https://community.glideapps.com/u/heidikruger)
#### Post date: [March 8, 2024, 1:31pm UTC](https://community.glideapps.com/t/javascript-not-running/71518/4 "2024-03-08T13:31:54Z")

</div>

Hi Jeff. Thank you for your reply. I am now getting a result. But the result still included duplicates. So I guess the function is not working properly.  
As to you question - My p1 parameter is a Joined List column.

This is what my code looks like after the change:

```auto
let arr = p1.split(',');
let unique = [];
arr.forEach(function (element) {
    if (!unique.includes(element)) {
        unique.push(element);
    }
});
return unique.join(',');

```

This is the p1 parameter value - duplicates marked in bold:  
**CN6-CI612** , **CN5-CI512** , **CN6-CI612** , CN6-CI632, **CN5-CI512** , CN5-CI532

This is my output:  
**CN6-CI612** , CN5-CI512, **CN6-CI612** , CN6-CI632, CN5-CI532

---

<div class="post-metadata">

### Author: ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)
#### Post date: [March 8, 2024, 1:41pm UTC](https://community.glideapps.com/t/javascript-not-running/71518/5 "2024-03-08T13:41:22Z")

</div>

So it appears to be mostly working. Your code looks good. Do you maybe have any extra spaces in one of your ‘CN6-CI612’ items? You could maybe try trimming ‘element’ in the IF and when you do the Push.

Actually, it might be the space. The first element does not have a leading space, but the rest do.

---

<div class="post-metadata">

### Author: ![heidikruger](https://avatars.discourse-cdn.com/v4/letter/h/c37758/32.png) [@heidikruger](https://community.glideapps.com/u/heidikruger)
#### Post date: [March 8, 2024, 1:57pm UTC](https://community.glideapps.com/t/javascript-not-running/71518/6 "2024-03-08T13:57:05Z")

</div>

Works perfectly now! Thank you Jeff

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [March 8, 2024, 2:17pm UTC](https://community.glideapps.com/t/javascript-not-running/71518/7 "2024-03-08T14:17:53Z")

</div>

You can use a split text column to convert your string into an array, and then use this column to get only unique elements.

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

---

<div class="post-metadata">

### Author: ![heidikruger](https://avatars.discourse-cdn.com/v4/letter/h/c37758/32.png) [@heidikruger](https://community.glideapps.com/u/heidikruger)
#### Post date: [March 8, 2024, 2:29pm UTC](https://community.glideapps.com/t/javascript-not-running/71518/8 "2024-03-08T14:29:20Z")

</div>

O brilliant! I did not even think of that. Thank you
