JSON Convert all values to lowercase

JSON Convert all values to lowercase

There is no inbuilt method in javascript to convert all values to lowercase. In this case, you have to use some logic to convert all values to lowercase.

The following example will demonstrate how to convert all values to lowercase.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <h1>JSON Convert all values to lowercase</h1> <button onclick="myFunction()">Click Me</button> <script> var data = [ { "name": "Mike", "age": 24, "country": "England" }, { "name": "Jade", "age": 22, "country": "Mexico" } ] function myFunction(){ for(var i = 0; i < data.length; i++){ for (var key in data[i]) { if(typeof data[i][key] == "string"){ data[i][key] = data[i][key].toLowerCase(); } } } console.log(data); } </script> </body> </html>

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author