Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js delete duplicates from array

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

let unique = [...new Set(names)];
console.log(unique); // 'John', 'Paul', 'George', 'Ringo'
Comment

js delete duplicates from array

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

function removeDups(names) {
  let unique = {};
  names.forEach(function(i) {
    if(!unique[i]) {
      unique[i] = true;
    }
  });
  return Object.keys(unique);
}

removeDups(names); // // 'John', 'Paul', 'George', 'Ringo'
Comment

how to delete duplicate elements in an array in javascript

//Other Mathod using Foreach and includes
let chars = ['A', 'B', 'A', 'C', 'B'];

let uniqueChars = [];
chars.forEach((c) => {
    if (!uniqueChars.includes(c)) {
        uniqueChars.push(c);
    }
});

console.log(uniqueChars);
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

PREVIOUS NEXT
Code Example
Javascript :: importing react 
Javascript :: change text using javascript 
Javascript :: map through keys javascript 
Javascript :: js 1d index to 2d coord 
Javascript :: JS get number of classes in html 
Javascript :: discord js sending a message to a specific channel 
Javascript :: jquery scroll to div callback 
Javascript :: Sailsdock 
Javascript :: get next month js 
Javascript :: db.json 
Javascript :: multer rename file 
Javascript :: javascript split array into chunks 
Javascript :: remove null values from json object in javascript 
Javascript :: Error: Expected "payload" to be a plain object. at validate 
Javascript :: javascript get cookie 
Javascript :: first non repeating character javascript 
Javascript :: dynamics js search another entity 
Javascript :: javascript go to url 
Javascript :: how to clamp a value by modulus 
Javascript :: external linking of JavaScript in html 
Javascript :: jquery get label from select 
Javascript :: How find a specific character in js 
Javascript :: get element by xpath in javascript 
Javascript :: image url to file js 
Javascript :: js set get first value 
Javascript :: react-native init AwesomeProject change port 
Javascript :: Codewars Convert a String to a Number! 
Javascript :: max_safe_integer 
Javascript :: usestate hook for checkbox check and uncheck 
Javascript :: jquery get document height 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =