I have a data.js
file which contains an object like this:
var somedata = {
"": "test",
"51": "f",
"123": "test1",
"67": "test2",
"hello": "ghr",
...
}
module.exports = somedata;
Unfortunately, this object gets reordered, and the order is quite important for the application. At this point, somebody suggested using Maps
thus, it became:
var somedata = new Map(Object.entries({
"": "test",
"51": "f",
"123": "test1",
"67": "test2",
"hello": "ghr",
...
}))
module.exports = somedata;
ahh well, that didn't work either (or maybe I just didn't get maps). Hence, for the time being I built a workaround where I actually read the file using regex and put it into a map object to preserve object order. Unfortunately, as data.js
is becoming quite big, this approach is quite time consuming. At which point I felt that I was looking at things the wrong way around.
My question: Is there a way to preserve object order somehow? Or at least a faster workaround than parsing the entire file?