
- 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
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 Articles
- 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
- Number prime test in JavaScript by creating a custom function?
- How to define custom sort function in JavaScript?
- Create a Calculator 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
- Create HTML Document with Custom URL for the document in JavaScript
- How to create a function from a string in JavaScript?
- Custom len() Function In Python
- How to create custom select boxes with CSS and JavaScript?
- How to create a custom listview in android?

Advertisements