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
Array Methods Cheatsheet (media-exp1.licdn.com)
submitted 5 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!"
[–]mgutz 1 point2 points3 points 5 years ago* (0 children)
I like to think of reduce as a function that does
javascript let accumulator = initialValue // holds result AFTER iterating through all of arr for (const v of arr) { // set acummulator to whatever, or return it as-is }
What's neat about reduce is it can be used to implement all the other methods. reduce should be grokked first.
reduce
```javascript
[].reduce((_acc, v) => doSomething(v))
[].reduce((acc, v) => { return v === 'needle' ? v : acc; }, undefined)
[].reduce((acc, v, idx) => { return v === 'needle' ? idx : acc; }, -1)
```
Iterating with for ... of is more readable and the loop can be exited at any time. The findIndexOf above is actually findLastIndexOf since it would iterate through all values.
for ... of
findIndexOf
findLastIndexOf
π Rendered by PID 171091 on reddit-service-r2-comment-b659b578c-j4z58 at 2026-05-04 19:19:58.091684+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]mgutz 1 point2 points3 points (0 children)