假设以下是我们的对象-
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' }