Return to Snippet

Revision: 80328
at March 5, 2020 18:32 by jlustre


Initial Title
Get unique values from an array

Initial Description
This code is used to get the unique values of an array.

Initial Code
const array = [1, 1, 1, 3, 3, 2, 2];

var unique = array.filter((element, index) => {
  return array.indexOf(element) === index;
});

//unique.toString();
for(var i=0;i<unique.length;i++){
	console.log(unique[i]+"\r\n<br>");
}

Initial Tags
array, javascript

Initial Language
JavaScript

Initial URL