- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Create a custom toLowerCase() function in JavaScript
We are required to write a JavaScript String function that overwrite the default toLowerCase() and should have the same functionality as the default function.
Let's write the code for this function −
Example
const str = 'Some UpPerCAsE LeTTeRs!!!'; const toLowerCase = function(){ let str = ''; for(let i = 0; i < this.length; i++){ const ascii = this[i].charCodeAt(); if(ascii >= 65 && ascii <= 90){ str += String.fromCharCode(ascii + 32); }else{ str += this[i]; }; }; return str; }; String.prototype.toLowerCase = toLowerCase; console.log(str.toLowerCase());
Output
The output in the console will be −
some uppercase letters!!!
Advertisements