-2
let getNonDuplicates = [1,2,3,4,2,3,4,5]; // Here's my example array

the result I needed is to get 1 & 5 since those are the data that don't have duplicates

let resultMustBe = [1,5];

1 Answers1

2

You could use filter method, to filter the array, based on the condition that index of an element from beginning is equal to index of the same element from the last. It means that the element is unique in the array.

let arr = [1,2,3,4,2,3,4,5];

let res = arr.filter(e=>arr.indexOf(e)===arr.lastIndexOf(e));

console.log(res);
TechySharnav
  • 4,869
  • 2
  • 11
  • 29