If i have an object say
object1 = {
a: "val1"
b: "val2",
c: "val3",
}
I want to swap properties to get
object1={
b:"val2"
a:"val1",
c:"val3",
}
Thanks in advance
If i have an object say
object1 = {
a: "val1"
b: "val2",
c: "val3",
}
I want to swap properties to get
object1={
b:"val2"
a:"val1",
c:"val3",
}
Thanks in advance
The easiest thing to do is manually rearrange properties:
var object1 = {
a: "val1",
b: "val2",
c: "val3",
}
object1 = {
b: object1.b,
a: object1.a,
c: object1.c,
}
console.log(object1);
There is no sorting of a JavaScript Object properties and no particular order maintained by existing browser vendors except for that of Microsoft IE+.
This means that you cannot arrange or rearrange object properties at all. The object keys order arbitrary and is not maintained anyhow. It simply is not a language requirement and the keys order maintenance decision is up to implementation party.