I am trying to create a new object by taking reference of an existing object as done below.
var c = {
"pstn_id": 1,
"pstn_ds": 1,
"pstn_titl_tx": 1,
"job_id": 1,
"ov_co_id":1,
"efcv_bgdt":1
};
var newObj ={};
Object.getOwnPropertyNames(c).forEach(function(ce){
newObj["_"+ce] = "$"+ce;
});
console.log(newObj);
//console
[object Object] {
_efcv_bgdt: "$efcv_bgdt",
_job_id: "$job_id",
_ov_co_id: "$ov_co_id",
_pstn_ds: "$pstn_ds",
_pstn_id: "$pstn_id",
_pstn_titl_tx: "$pstn_titl_tx"
}
This console shows an object but not in the order of the reference object I have used
Why is the newly created property names not in the order of their looping.
I want it in this order,
{
_pstn_id: "$pstn_id",
_pstn_ds: "$pstn_ds",
_pstn_titl_tx: "$pstn_titl_tx",
_job_id: "$job_id",
_ov_co_id: "$ov_co_id",
_efcv_bgdt: "$efcv_bgdt"
}