java script

shid077
Tera Contributor

var arrTest = [ 4, 14, 4, 3, 44, 3, 12, 1, 2, 33];

 

to remove the duplicate from the above array what line of code i have to write in JavaScript.

 

Please suggest.

4 REPLIES 4

Ct111
Giga Sage

Azem
Tera Guru

Hi @shid077 

 

Try the script below and let me know your luck.

 

var arrTest = [ 4, 14, 4, 3, 44, 3, 12, 1, 2, 33];
  var arrayUtil = new ArrayUtil().unique(arrTest);
  gs.info(arrayUtil); //Log the new array

 

Kind Regards,

Harish Bainsla
Kilo Patron
Kilo Patron

var arrTest = [4, 14, 4, 3, 44, 3, 12, 1, 2, 33];
var uniqueArr = Array.from(new Set(arrTest));

console.log(uniqueArr);

Appli
Mega Sage
Mega Sage

Hi, you may also try this one:

var Array1 = [4, 14, 4, 3, 44, 3, 12, 1, 2, 33];
// Function to get unique values from an array
function getUniqueValues(arr) {
    return arr.filter(function(value, index, self) {
        return self.indexOf(value) === index;
    });
}
var Array2 = getUniqueValues(Array1);
// Display unique values
gs.info(Array2);
Hope it helps