We're serializing a form using serializeObject
and then storing this into local storage as a JSON encoded string. When we decode this back out of LocalStorage, we have keys with the name of flight[inbound][0][iso]
and flight[outbound][1][date]
etc. This makes it difficult to properly loop through later on (in JavaScript) as we need to now repopulate the form with the stored data.
Is there a way of further decoding these key names into sub-objects? For example:
flight[outbound][0][datetime] = "Something";
flight[outbound][0][from] = "Something";
flight[outbound][0][to] = "Something";
flight[outbound][0][carrier] = "Something";
flight[inbound][0][datetime] = "Something";
flight[inbound][0][from] = "Something";
flight[inbound][0][to] = "Something";
flight[inbound][0][carrier] = "Something";
Should turn into:
flight = {
outbound: {
0: {
datetime: "Something",
from: "Something",
to: "Something",
carrier: "Something",
}
},
inbound: {
0: {
datetime: "Something else",
from: "Something else",
to: "Something else",
carrier: "Something else",
}
}
}