function getOnlyUniqueValuesInArray(array) { const arrayLen = array.length; /** @type {Map} */ const map = new Map(); for (let i = 0 ; i < arrayLen ; i++) { const value = array[i]; map.set(value, map.getOrInsert(value, 0) + 1); } return array.filter(value => map.get(value) === 1); } console.assert( getOnlyUniqueValuesInArray([10, 2, 3, 4, 5, 10, 6, 5, 0, 9, 2]) .join(',') === [3, 4, 6, 0, 9].join(',') ); console.assert( getOnlyUniqueValuesInArray(['10', 2, 3, 4, 5, 10, 'test', 5, 0, 9, 2]) .join(',') === ['10', 3, 4, 10, 'test', 0, 9].join(',') );