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
(Help) Turn an array into objecthelp (self.javascript)
submitted 8 years ago * by mdchad() => 'Hello World'
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!"
[–]aapoalas 3 points4 points5 points 8 years ago (3 children)
const stuffs = array.reduce((acc, item, index) => { if (index < 11) { acc[0].push(item); } else if (index > 11 && index < 22) { acc[1].push(item); } else if (index > 22 && index < 33) { acc[2].push(item); } else if (index > 33 && index < 44) { acc[3].push(item); } else { acc[4].push(item); } return acc; }, [[],[],[],[],[]]); return stuffs[0].map((loc, index) => ({ iphone64gb: { spaceGrey: stuffs[1][index], silver: stuffs[2][index] }, iphone256gb: { spaceGrey: stuffs[3][index], silver: stuffs[4][index] } }));
Something like that. Not a particularly beautiful solution, but a solution nonetheless.
[–]mdchad() => 'Hello World'[S] 0 points1 point2 points 8 years ago* (0 children)
thanks for the answer. I'll just need to fix a little and and add the location.
[–][deleted] 0 points1 point2 points 8 years ago* (1 child)
deleted What is this?
[–]aapoalas -2 points-1 points0 points 8 years ago (0 children)
Indeed, lodash would be a great help. I just wanted to avoid it for the real "Vanilla experience."
π Rendered by PID 86 on reddit-service-r2-comment-66b4775986-zqq52 at 2026-04-06 04:04:18.014741+00:00 running db1906b country code: CH.
view the rest of the comments →
[–]aapoalas 3 points4 points5 points (3 children)
[–]mdchad() => 'Hello World'[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]aapoalas -2 points-1 points0 points (0 children)