Reputation: 439
I am getting data like this
4706:"APN"
4743:"Owner Name"
4754:"Situs Address"
6231 :"Mailing Address"
in a javascript object. When I copy this into new object it give same output while I want to replace it with my keys like this
0:"APN"
1:"Owner Name"
2:"Situs Address"
3 :"Mailing Address"
Is it possible to do that ? I am copying this object in tblheader
tblHeader=features[i].attributes.fields.values;
Upvotes: 0
Views: 41
Reputation: 410
oldObject =
{
4706:"APN",
4743:"Owner Name",
4754:"Situs Address",
6231 :"Mailing Address"
};
newObject = {}
Object.keys(oldObject).map(function(key, index) {
newObject[index] = oldObject[key];
});
console.log(newObject)
Upvotes: 1
Reputation: 22500
Try with Object.values()
method ,its create the array of values .And use Array#forEach()
for iteate the array and append with new object
var arr = {
4706: "APN",
4743: "Owner Name",
4754: "Situs Address",
6231: "Mailing Address",
}
var res ={};
Object.values(arr).forEach(function(a,b){
res[b]=a
})
console.log(res)
Upvotes: 1