185
rated 0 times
[
189]
[
4]
/ answers: 1 / hits: 73315
/ 11 Years ago, fri, october 25, 2013, 12:00:00
I am trying to create the following data structure in javascript:
d = {foo: [3, 77, 100], bar: [10], baz: [99], biff: [10]}
My starting data structure is a a list of dictionaries:
input = [{key: foo, val: 3}, {key: bar, val: 10}, {key: foo, val: 100}, {key: baz, val: 99}, {key: biff, val: 10}, {key: foo, val: 77]
How can I generate my desired data structure? The following code doesn't seem to append values to the value array.
var d = {}
for (var i in input) {
var datum = input[i];
d[datum.key] = datum.val
}
More From » javascript