Obtaining a Array with Unique Items

I want a array with unique items.
For example,
{1, 2, 2, 3, ,4 ,4, 4}  => {1, 2, 3, 4}
I found looking good javascript, but it doesn’t work in unity script. And I’m not able to modify it.
Could help me to modify this script?

function unique(array) {
 var storage = {};
 var uniqueArray = [];
 var i,value;
 for ( i=0; i<array.length; i++) {
    value = array*;*

if (!(value in storage)) {
* storage[value] = true;*
return uniqueArray;

This only is guaranteed to work when your original array is sorted (as in your example):

var lastValue = Mathf.Infinity;
for (i=0; i < array.length; ++i) {
 if (array *!= lastValue) {*

lastValue = array*;*
I don’t know Javascript well so I’m just copying your syntax, but
the logic is sound (when sorted)… lastvalue remembers the last unique value from the original array, and so only uniques get placed in the new one. (Edit note: this is only partial code, i didn’t copy all of the code from your example in case you are new to programming, i just did the important part)