Here is the Javascript Equivalent to array_unique()

This Javascript function performs in the same way as the PHP function array_unique($array). The function returns the array with duplicate array items removed leaving each element unique.

// return the array with duplicate items removed just like the php function array_unique()

function array_unique($a) {
    return [ Set($a)];

$array = [1,2,3,3,3,6,4,8,3,4,6,5,0,9,0,2,6,03,6,4,7,5,8,6,9,7,0,2,3,10,"hello", "world"]; $array = array_unique($array); </script> 

After the Javascript function call to array_unique($array) the value of $array is:

With other functions:

$array = array_unique($array).sort();

Produces the result:

However this array is mixed with both numeric and string data. The native sort() function places "10" before "2".

If you want a natural sort, use the custom Javascript Equivalent to PHP's natsort():

$array = array_unique(natsort($array));

Produces the result:


Copyright © Website Development | Disclaimer | Privacy Policy | Terms of Use