
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert mixed case string to lower case in JavaScript
Problem
We are required to write a JavaScript function convertToLower() that takes in a string method that converts the string it is being called upon into lowercase string and returns the new string.
For example, if the input to the function is
Input
const str = 'ABcD123';
Output
const output = 'abcd123';
Example
Following is the code −
const str = 'ABcD123'; String.prototype.convertToLower = function(){ let res = ''; for(let i = 0; i < this.length; i++){ const el = this[i]; const code = el.charCodeAt(0); if(code >= 65 && code <= 90){ res += String.fromCharCode(code + 32); }else{ res += el; }; }; return res; }; console.log(str.convertToLower());
Output
abcd123
- Related Questions & Answers
- How to convert Lower case to Upper Case using C#?
- How to convert Upper case to Lower Case using C#?
- How to convert a string into the lower case using JavaScript?
- How to convert std::string to lower case in C++?
- Java String to Lower Case example.
- MySQL Query to change lower case to upper case?
- How to convert a string to camel case in JavaScript?
- PHP – Make a lower case string using mb_strtolower()
- Convert a C++ String to Upper Case
- C program to convert upper case to lower and vice versa by using string concepts
- How to convert a string into upper case using JavaScript?
- How to convert string to title case in C#?
- Lower case column names with MySQL SELECT?
- Casting a string to snake case - JavaScript
- How to use case-insensitive switch-case in JavaScript?
Advertisements