Here's my array (from chrome console) :
Here's the pertinent part of code :
console.log(hours);
var data = JSON.stringify(hours);
console.log(data);
In chrome's console i get []
from the last line. I should get {'Mon':{...}...}
Here is the minimal amount of javascript to reproduce the issue
var test = [];
test["11h30"] = "15h00"
test["18h30"] = "21h30"
console.log(test);
console.log(JSON.stringify(test)); // outputs []
I tried some others stuff like Convert array to JSON or Convert javascript object or array to json for ajax data but the problem remains :/
Thanks for help.
length
says zero and the properties are named. – Jamiec Feb 13 at 13:40[]
) when you actually need objects ({}
). In JavaScript if you want to use non-numerical keys (e.g. "11h30") you'll need to use an object instead. – Juhana Feb 13 at 13:40