Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Remove duplicate items form array using reduce() method.

const names = [
	'shibu',
	'neymar',
	'vinicius',
	'pattinson',
	'ronaldo',
	'shibu',
	'neymar',
	'pattinson',
	'diCaprio'
];

let onlyName = names.reduce((accumulator, currentValue) => {
	if (accumulator.indexOf(currentValue) === -1) {
		accumulator.push(currentValue);
	}
	return accumulator;
}, []);

console.log(onlyName);

//Expected result => ['shibu', 'neymar', 'vinicius', 'pattinson', 'ronaldo', 'diCaprio'
 
PREVIOUS NEXT
Tagged: #Remove #duplicate #items #form #array
ADD COMMENT
Topic
Name
1+2 =