Melt elements from ordered dictionary with JavaScript

I am very new to JavaScript. Could someone help me with translating a python code to JavaScript? Deeply appreciated.

I have a ordered dictionary:

dict1 = [OrderedDict([('emo', 'StimusEmo/2205.bmp')]), OrderedDict([('emo', 'StimusEmo/9185.bmp')]), OrderedDict([('emo', 'StimusEmo/6313.bmp')]), OrderedDict([('emo', 'StimusEmo/9252.bmp')]), OrderedDict([('emo', 'StimusEmo/3230.bmp')]), OrderedDict([('emo', 'StimusEmo/1300.bmp')]), OrderedDict([('emo', 'StimusEmo/9921.bmp')])]

I want to use JavaScript code to make it as (if JavaScript recognize dictionary):

dict2 = {'emo': ['StimusEmo/2205.bmp', 'StimusEmo/9185.bmp', 'StimusEmo/6313.bmp', 'StimusEmo/9252.bmp', 'StimusEmo/3230.bmp', 'StimusEmo/1300.bmp', 'StimusEmo/9921.bmp']}

Or just a list:

emo = ['StimusEmo/2205.bmp', 'StimusEmo/9185.bmp', 'StimusEmo/6313.bmp', 'StimusEmo/9252.bmp', 'StimusEmo/3230.bmp', 'StimusEmo/1300.bmp', 'StimusEmo/9921.bmp']

I have written the python code which successfully did the work:

for k in dic1[0]:
    dic2[k] = [d[k] for d in dic1]

My automatic JavaScript translator gives me this:

for (var k, _pj_c = 0, _pj_a = dict1[0], _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
    k = _pj_a[_pj_c];
    dict2[k] = function () {
    var _pj_d = [], _pj_e = dict1;
    for (var _pj_f = 0, _pj_g = _pj_e.length; (_pj_f < _pj_g); _pj_f += 1) {
        var d = _pj_e[_pj_f];
        _pj_d.push(d[k]);
    }
    return _pj_d;
}
.call(this);
}

However, this JavaScript yield error as: .length is not identified. I changed the .length to my ordered dictionary length. Still not working.

I am sorry I have almost no experience with JavaScript. I thought I would provide the automated translation to help to spark the solution. Anything can help. Thanks!

Answer

You can do something like that:

const dic1 = [
    {'emo': 'StimusEmo/2205.bmp'},
    {'emo': 'StimusEmo/9185.bmp'},
    {'emo': 'StimusEmo/6313.bmp'},
    {'emo': 'StimusEmo/9252.bmp'},
    {'emo': 'StimusEmo/3230.bmp'},
    {'emo': 'StimusEmo/1300.bmp'},
    {'emo': 'StimusEmo/9921.bmp'},
]

const dic2 = {};
dic1.forEach((dic) => {
    const key = Object.keys(dic)[0];
    const arr = dic2[key] || (dic2[key] = []);
    arr.push(dic[key]);
});

console.log(dic2);
// Outputs
// {
//   emo: ["StimusEmo/2205.bmp", "StimusEmo/9185.bmp", "StimusEmo/6313.bmp", "StimusEmo/9252.bmp", "StimusEmo/3230.bmp", "StimusEmo/1300.bmp", "StimusEmo/9921.bmp"]
// }