JSON Convert all keys to UPPERCASE

JSON Convert all keys to UPPERCASE

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

The following example will demonstrate how to convert all keys to UPPERCASE.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <h1>JSON Convert all keys to UPPERCASE</h1> <button onclick="myFunction()">Click Me</button> <script> var data = [ { "name": "Mike", "age": 36 }, { "NAME": "Jade", "AGE": 24 } ]; function myFunction(){ for(var i = 0; i < data.length; i++){ for (var key in data[i]) { if(key.toUpperCase() !== key){ data[i][key.toUpperCase()] = data[i][key]; delete data[i][key]; } } } 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