Advertisement
Savelyev_Vyacheslav

getUniq

Nov 6th, 2022 (edited)
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getUniqueArray(_array)
  2. {// https://thispointer.com/javascript-get-unique-values-in-an-array/
  3.   // in the newArray get only the elements which pass the test implemented by the filter function.
  4.   // the test is to check if the element's index is same as the index passed in the argument.
  5.   let newArray = _array.filter((element, index, array) => array.indexOf(element) === index);
  6.   return newArray
  7. }
  8. let myArray = ["Hello", "This", "Is","Language","This", "Is" ];
  9. ss.info(getUniqueArray(myArray))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement