So recently I’ve been working on a JSON project in which I wanted to find the number of unique songs I had played on Spotify, and I ran into this problem.

How can I find out if I have already gotten that song?

Here’s my answer, simplified into letters:

```
x = ["a", "b", "c", "c"] // x is the array we're looping through
y = [] // y is the array which we want to put each unique song in
for(var i = 0; i < x.length; i++) { // a for loop to loop through the array
if(y.indexOf(x[i]) === -1) {
y.push(x[i]) // this pushes the value to y
}
}
```

The only really complicated line is the if conditional statement. What this line basically does is it grabs the `y`

array and asks what the index is of `x[i]`

(which would be whatever value it is currently looping through e.g. `x["a"] = 0`

because that’s the index at which “a” is at.). If that item does not exist in the list, `indexOf`

returns -1 which is why we compare it to -1. This is clear if you try running something like this in the console:

```
y = ["a", "b", "c"]
y.indexOf('z')
-> -1
```

Anyways, that’s the answer and explanation. I hope it helps anyone trying to create their own project and are having this problem.

*Note: This concept was probably taught sometime in the codecademy learning exercises, but I don’t remember it *