मान लीजिए निम्नलिखित हमारा ऑब्जेक्ट है:
var details = {
"STUDENTNAME": "John",
"STUDENTAGE": 21,
"STUDENTCOUNTRYNAME": "US"
}
जैसा कि आप ऊपर देख सकते हैं, कीज़ कैपिटल केस में हैं। हमें इन सभी कीज़ को लोअरकेस में बदलना है। इसके लिए toLowerCase() का उपयोग करें।
उदाहरण
निम्नलिखित कोड है:
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);
उपरोक्त प्रोग्राम को चलाने के लिए, आपको निम्नलिखित कमांड का उपयोग करना होगा:
node fileName.js
यहां, मेरा फ़ाइल नाम demo297.js है।
आउटपुट
यह कंसोल पर निम्नलिखिक आउटपुट देगा:
PS C:\Users\Amit\javascript-code> node demo297.js
{ studentcountryname: 'US', studentage: 21, studentname: 'John' }