I have the following JSON and I am trying to alter it to have the same key and value string:
var icons = {
"123": 63103,
"alarm-fill": 61697,
"alarm": 61698
}
I'm trying the following code:
var newIcons = [];
for (var key in icons) {
if (icons.hasOwnProperty(key)) {
newIcons.key = key;
}
}
console.log(newIcons);
It should return the following:
{
"123": "123",
"alarm-fill": "alarm-fill",
"alarm": "alarm"
}
CodePudding user response:
var newIcons = {};
for (var key in icons) {
newIcons[key] = key;
}
console.log(newIcons);