
- 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 last vowel - 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';
Example
Following is the code −
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
Following is the output in the console −
Ths s n exampl strng
- Related Articles
- Deleting the last vowel from a string in JavaScript
- Vowel gaps array in JavaScript
- Counting occurrences of vowel, consonants - JavaScript
- Distance to nearest vowel in a string - JavaScript
- Removing Negatives from Array in JavaScript
- Removing already listed intervals in JavaScript
- Vowel, other characters and consonant difference in a string JavaScript
- Removing duplicate objects from array in JavaScript
- JavaScript Algorithm - Removing Negatives from the Array
- Removing 0s from start and end - JavaScript
- Removing redundant elements from array altogether - JavaScript
- Removing a node in a Javascript Tree
- Removing parentheses from mathematical expressions in JavaScript
- Arranging lexicographically and removing whitespaces in JavaScript
- Removing punctuations from a string using JavaScript

Advertisements