Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript remove duplicates

var arr = ["apple", "mango", "apple", "orange", "mango", "mango"];
  
function removeDuplicates(arr) {
	return arr.filter((item, 
		index) => arr.indexOf(item) === index);
}
  
console.log(removeDuplicates(arr)); // ["apple", "mango", "orange"]
Comment

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'));
Comment

remove the duplicate character in string js

function removeDuplicate(str, letSingleChar = false)  {
    let string = str;
    for (element of string) {
        const re = new RegExp(element, 'g');
        if (string.match(re)?.length > 1) {
          if (letSingleChar == true) {
            string = [...new Set(string.split(''))].join('');
          } else 
            string = string.replace(re, '');
        }
    }
    return string;
} 

console.log(removeDuplicate("Hello World", true)) // Helo Wrd
console.log(removeDuplicate("Hello World", false )) // He Wrd
Comment

remove repeated characters from a string in javascript

const unrepeated = (str) => [...new Set(str)].join('');

unrepeated("hello"); //➞ "helo"
unrepeated("aaaaabbbbbb"); //➞ "ab"
unrepeated("11112222223333!!!??"); //➞ "123!?"
Comment

javascript remove duplicates

uniq = [...new Set(array)];
Comment

JavaScript remove duplicate items

function onlyUnique(value, index, self) {
  return self.indexOf(value) === index;
}

// usage example:
let a = ['a', 1, 'a', 2, '1'];
let unique = a.filter(onlyUnique);

console.log(unique); // ['a', 1, 2, '1']
Comment

remove duplicates javascript

function withoutDuplicates (arr) {
  return [...new Set(arr)];
}
Comment

remove duplicate values from string in javascript

const names = ['John', 'Paul', 'George', 'Ringo', 'John'];

let unique = [...new Set(names)];
console.log(unique); 
Comment

remove duplicate name from array javascript

const allNames = ['Nathan', 'Clara ', 'Nathan', 'Fowler', 'Mitchell', 'Fowler', 'Clara ', 'Drake', 'Fowler', 'Clyde ', 'Mitchell', 'Clyde '];

function checkName(names) {
  const uniqueName = [];
  for (let i = 0; i < names.length; i++) {
    const nameIndex = names[i];
    if (uniqueName.includes(nameIndex) == false) {
      uniqueName.push(nameIndex);
    }
  }
  return uniqueName;
}

const uniqueNames = checkName(allNames);
console.log(uniqueNames);
Comment

how to remove duplicates in js

const names = ['John', 'Paul', 'George', 'Ringo', 'John'];

let unique = [...new Set(names)];
console.log(unique);
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript delete element of an array 
Javascript :: nodejs date add days 
Javascript :: liquid filter 
Javascript :: ant design form validation in the modal 
Javascript :: some in js 
Javascript :: createtextnode javascript 
Javascript :: js sort array 
Javascript :: what is a heap in javascript 
Javascript :: javascript unicode 
Javascript :: how to create a variable in javascript 
Javascript :: react native modal 
Javascript :: serviceworker in angular 
Javascript :: max array 
Javascript :: react native splash screen 
Javascript :: vuejs jwt authentication example 
Javascript :: vue 
Javascript :: js exports 
Javascript :: what is bom in javascript 
Javascript :: + sign javascript 
Javascript :: disadvantages of array 
Javascript :: filter table search 
Javascript :: how to make a quiz in javascript 
Javascript :: js 2d array includes 
Javascript :: js access array value if exist 
Javascript :: array concat 
Javascript :: react native update helper 
Javascript :: es6 import 
Javascript :: == vs === javascript 
Javascript :: Texto unitário no node js 
Javascript :: js button to take current page screenshot 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =