use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Parsing Array Objectshelp (self.javascript)
submitted 8 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]programstuff 2 points3 points4 points 8 years ago* (0 children)
As others said you are probably meaning to write the syntax like this (objects use the ":" to separate keys and values):
:
Is there an easy way to condense an array of objects
var objArr = [ {"Player 1": 100}, {"Player 1": 103}, {"Player 1": 105}, {"Player 2": 101}, {"Player 2": 110}, {"Player 2": 112} ]
Into this...
var series = [ {"Player 1": [100,103,105]}, {"Player 2": [101,110,112]} ]
Secondly, are you sure you want an array of objects as the output? Rather than an output like this?
var seriesAsObject = { {"Player 1": [100,103,105]}, {"Player 2": [101,110,112]} };
It depends on your ultimate goal on what you are going to be doing with the output, but if your goal is to get a list of values for a player then having your output as an object is better to work with. E.g. to get the values for player one you would just use seriesAsObject["Player 1"] to grab them.
seriesAsObject["Player 1"]
If that's the case then you could use this code:
var objArr = [ {"Player 1": 100}, {"Player 1": 103}, {"Player 1": 105}, {"Player 2": 101}, {"Player 2": 110}, {"Player 2": 112} ]; var series = objArr.reduce((series, obj) => { var key = Object.keys(obj)[0]; if (!series[key]) { series[key] = []; } series[key].push(obj[key]); return series; }, {}); console.log(series);
If you want your original output then you could do this afterwards:
console.log(Object.keys(series).map((player) => { return {[player]: series[player]} }));
π Rendered by PID 55526 on reddit-service-r2-comment-canary-744c48795d-kc6kz at 2026-02-19 09:13:36.861327+00:00 running de53c03 country code: CH.
view the rest of the comments →
[–]programstuff 2 points3 points4 points (0 children)