

- 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
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!!!
- Related Questions & Answers
- How to create a custom function similar to find() method in JavaScript?
- Implementing a custom function like Array.prototype.filter() function in JavaScript
- How to create a custom object in JavaScript?
- Writing a custom URL shortener function in JavaScript
- Implementing custom function like String.prototype.split() function in JavaScript
- Create a Calculator function in JavaScript
- Number prime test in JavaScript by creating a custom function?
- How to define custom sort function in JavaScript?
- Implement a custom function similar to Array.prototype.includes() method using JavaScript
- Remove duplicate items from an array with a custom function in JavaScript
- Custom len() Function In Python
- Java String toLowerCase() method example.
- How to create a custom listview in android?
- How to create a custom jQuery Plugin?
- Validate Date in MySQL using a custom function
Advertisements