- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
What's the most efficient way to turn all the keys of an object to lower case - JavaScript?
Let’s say the following is our object −
var details = { "STUDENTNAME": "John", "STUDENTAGE": 21, "STUDENTCOUNTRYNAME": "US" }
As you can see above, the keys are in capital case. We need to turn all these keys to lower case. Use toLowerCase() for this.
Example
Following is the code −
var details = { "STUDENTNAME": "John", "STUDENTAGE": 21, "STUDENTCOUNTRYNAME": "US" } var tempKey, allKeysOfDetails = Object.keys(details); var numberOfKey = allKeysOfDetails.length; var allKeysToLowerCase = {} while (numberOfKey--) { tempKey = allKeysOfDetails[numberOfKey]; allKeysToLowerCase[tempKey.toLowerCase()] = details[tempKey]; } console.log(allKeysToLowerCase);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo297.js.
Output
This will produce the following output on console −
PS C:\Users\Amit\javascript-code> node demo297.js { studentcountryname: 'US', studentage: 21, studentname: 'John' }
- Related Articles
- What is the most efficient way to deep clone an object in JavaScript?
- What's the most efficient way to pull data from MySQL so that it is formatted with duplicate values
- What is the most efficient way to concatenate many Python strings together?
- What's the best way to detect a 'touch screen' device using JavaScript?
- What is the most efficient way of assigning all my HTML5 video sources as trusted without having to loop over all of them
- In MongoDB, what is the most efficient way to get the first and last document?
- What's the best way to open new browser window using JavaScript?
- What is the most efficient way to check the presence of a row in a MySQL table?
- What is the most efficient way to select a specific number of random rows in MySQL?
- Most efficient method to groupby on an array of objects - JavaScript
- Efficient way to remove all entries from MongoDB?
- Most efficient method to groupby on an array of objects in Javascript
- What's the simplest way to print a Java array?
- What's the best way to ensure a happy marriage?
- Is there a way to print all methods of an object in JavaScript?

Advertisements