Skip to content

Instantly share code, notes, and snippets.

@ali-master
Created January 4, 2017 09:35
Show Gist options
  • Save ali-master/0518c7dd98ca98206dde19c62dc01ada to your computer and use it in GitHub Desktop.
Save ali-master/0518c7dd98ca98206dde19c62dc01ada to your computer and use it in GitHub Desktop.
JavaScript Array Unique Item

JavaScript Array Unique Item

// ES6
const uniq = (userArray) => {
  const unique = {};
  userArray.forEach((unusedValue, index) => { unique[userArray[index]] = true; });
  return Object.keys(unique);
};

Usage

const uni = uniq([1,2,3,3,4,5,1,2,5]); // return: [1,2,3,4,5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment