- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Deleting the last vowel from a string in JavaScript
We are required to write a JavaScript function that takes in a string and returns a new string with the last vowel of each word removed.
For example: If the string is −
const str = 'This is an example string';
Then the output should be −
const output = 'Ths s n exampl strng';
Therefore, let’s write the code for this function −
Example
The code for this will be −
const str = 'This is an example string'; const removeLast = word => { const lastIndex = el => word.lastIndexOf(el); const ind = Math.max(lastIndex('a'), lastIndex('e'), lastIndex('i'), lastIndex('o'), lastIndex('u')); return word.substr(0, ind) + word.substr(ind+1, word.length); } const removeLastVowel = str => { const strArr = str.split(' '); return strArr.reduce((acc, val) => { return acc.concat(removeLast(val)); }, []).join(' '); }; console.log(removeLastVowel(str));
Output
The output in the console will be −
Ths s n exampl strng
- Related Articles
- Removing last vowel - JavaScript
- Distance to nearest vowel in a string - JavaScript
- Vowel, other characters and consonant difference in a string JavaScript
- Finding the length of longest vowel substring in a string using JavaScript
- Vowel gaps array in JavaScript
- How to remove the last character from a string in Java?
- Alternate vowel and consonant string in C++
- Alternate vowel and consonant string in C/C++?
- Count the nodes of the tree whose weighted string contains a vowel in C++
- How to get last 12 digits from a string in MySQL?
- Check whether we can form string2 by deleting some characters from string1 without reordering the characters of any string - JavaScript
- Counting occurrences of vowel, consonants - JavaScript
- Deleting partial data from a field in MySQL?
- How to extract the last n characters from a string using Java?
- How to remove only last character from a string vector in R?

Advertisements