
- 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
Converting any string into camel case with JavaScript removing whitespace as well
In order to convert string into camel case, you need to lowercase the first letter of the word and the first letter of the remaining words must be in capital.
Following is the code to convert any string into camel case −
Example
function convertStringToCamelCase(sentence) { return sentence.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function(camelCaseMatch, i) { if (+camelCaseMatch === 0) return ""; return i === 0 ? camelCaseMatch.toLowerCase() : camelCaseMatch.toUpperCase(); }); } console.log(convertStringToCamelCase("Add two variables"));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo104.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo104.js addTwoVariables
- Related Articles
- Converting whitespace string to url in JavaScript
- Converting any case to camelCase in JavaScript
- How to convert a string to camel case in JavaScript?
- Sentence Case of a given Camel cased String
- How do we split a string with any whitespace chars as delimiters using java?
- Converting strings to snake case in JavaScript
- How to convert a string into upper case using JavaScript?
- Converting string to a binary string - JavaScript
- How to filter String stream and map to lower case in Java? Perform sort as well.
- Breaking a string into chunks of defined length and removing spaces using JavaScript
- Converting array into increasing sequence in JavaScript
- How to convert a string into the lower case using JavaScript?
- Write a program in Python to verify camel case string from the user, split camel cases, and store them in a new series
- Write down a python function to convert camel case to snake case?
- Converting days into years months and weeks - JavaScript

Advertisements