
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Removing consecutive duplicates from strings in an array using JavaScript
Problem
We are required to write a JavaScript function that takes in an array of strings. Our function should remove the duplicate characters that appear consecutively in the strings and return the new modified array of strings.
Example
Following is the code −
const arr = ["kelless", "keenness"]; const removeConsecutiveDuplicates = (arr = []) => { const map = []; const res = []; arr.map(el => { el.split('').reduce((acc, value, index, arr) => { if (arr[index] !== arr[index+1]) { map.push(arr[index]); } if (index === arr.length-1) { res.push(map.join('')); map.length = 0 } }, 0); }); return res; } console.log(removeConsecutiveDuplicates(arr));
Output
[ 'keles', 'kenes' ]
- Related Articles
- Removing duplicates and inserting empty strings in JavaScript
- Removing duplicates from a sorted array of literals in JavaScript
- Unique sort (removing duplicates and sorting an array) in JavaScript
- JavaScript Program for Removing Duplicates From An Unsorted Linked List
- Removing adjacent duplicates from a string in JavaScript
- Removing an element from an Array in Javascript
- Removing duplicates from tuple in Python
- Completely removing duplicate items from an array in JavaScript
- Using recursion to remove consecutive duplicate entries from an array in JavaScript
- Using recursion to remove consecutive duplicate entries from an array - JavaScript
- Javascript Program For Removing Duplicates From A Sorted Linked List
- Removing Negatives from Array in JavaScript
- Remove duplicates from an array keeping its length same in JavaScript
- Removing duplicates and keep one instance in JavaScript
- Removing duplicate objects from array in JavaScript

Advertisements