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;
1

2 Answers 2

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)

Sign up to request clarification or add additional context in comments.

4 Comments

It will keep same sequence ? Or will change it every time? As I will get data differently every time and need same sequence .
yes...is it same sequence . 0,1 are index of the values from object
last thing , can I get it in array of object form ? l
yes using Object.values(obj) .Its return the array with values of the object .i was added with reference link with answer
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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.