remove duplicate characters in a string javascript code example

Example 1: javascript remove duplicate letters in a string

function removeDuplicateCharacters(string) {
  return string
    .split('')
    .filter(function(item, pos, self) {
      return self.indexOf(item) == pos;
    })
    .join('');
}
console.log(removeDuplicateCharacters('baraban'));

Example 2: duplicate characters in a string javascript

const text = 'abcda'.split('')
text.some( (v, i, a) => {
  return a.lastIndexOf(v) !== i
}) // true

Example 3: remove duplicates strig javascript

const arr = [1, 2, [3, 4]];

// To flat single level array
arr.flat();
// is equivalent to
arr.reduce((acc, val) => acc.concat(val), []);
// [1, 2, 3, 4]

// or with decomposition syntax
const flattened = arr => [].concat(...arr);