0

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;
ephemeral
  • 429
  • 2
  • 7
  • 16

2 Answers2

1

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)
prasanth
  • 22,145
  • 4
  • 29
  • 53
1

Try this

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)
zennith
  • 410
  • 2
  • 5
  • 17