We would like to know how to map array values into a map.
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!-- w w w. jav a2 s . c o m-->
var a = [{abc: 1}, {def: 2}, {def: 42}, {def : 40}];
var o = {};
for (var i = 0, l = a.length; i < l; i++) {
var key = Object.keys(a[i]);
if (!o[key]) {
o[key] = [];
}
o[key].push(a[i][key]);
}
document.writeln(JSON.stringify(o));
</script>
</head>
<body>
</body>
</html>
The code above is rendered as follows: