- 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
How to move all capital letters to the beginning of the string in JavaScript?
Let’s say following is our string −
my name is JOHN SMITH
Use sort() along with regular expression /[A-Z]/ to move all capital letters to the beginning of the string/
Example
var moveAllCapitalLettersAtTheBeginning = [...' my name is JOHN SMITH '] .sort((value1, value2) => /[A-Z]/.test(value1) ? /[A-Z]/.test(value2) ? 0 : -1 : 0).join(' '); console.log("After moving the all capital letters at the beginning="); console.log(moveAllCapitalLettersAtTheBeginning);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo199.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo199.js After moving the all capital letters at the beginning= J O H N S M I T H m y n a m e i s
- Related Articles
- Move string capital letters to front maintaining the relative order - JavaScript
- How to move multiple elements to the beginning of the array in JavaScript?
- How can we print all the capital letters of a given string in Java?
- How to set the font to be displayed in small capital letters with JavaScript?
- How to get the maximum count of repeated letters in a string? JavaScript
- How to add a character to the beginning of every word in a string in JavaScript?
- How to find capital letters with Regex in MySQL?
- How to convert all uppercase letters in string to lowercase in Python?
- For the Hosts Locale how to convert a string to uppercase letters in JavaScript?
- How to input letters in capital letters in an edit box in Selenium with python?
- Moving all Upper case letters to the end of the String using Java RegEx
- How to invert case for all letters in a string in Python?
- Check for specific beginning or ending letters in a JavaScript function
- Insert the string at the beginning of all items in a list in Python
- For Hosts Locale how to convert a string to lowercase letters in JavaScript?

Advertisements