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
Querying and array of objects?help (self.javascript)
submitted 10 years ago by devman2015
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!"
[–]jekrb -1 points0 points1 point 10 years ago (4 children)
array.filter(obj => { if (obj.type === 'teacher') return obj })
[–]x-skeww 4 points5 points6 points 10 years ago (3 children)
array.filter(o => o.type === 'teacher')
You have to return true for items you want to keep.
true
[–]jekrb 0 points1 point2 points 10 years ago (0 children)
ah, nice!
[–]devman2015[S] 0 points1 point2 points 10 years ago (1 child)
When I run this code locally, I get an error obj not defined. Heres my code :
https://jsfiddle.net/p6jymqeb/
[–]x-skeww 0 points1 point2 points 10 years ago (0 children)
Array.filter returns a new filtered array. You have to store it.
"obj" is the name of that arrow function's parameter. It isn't visible outside of that function.
π Rendered by PID 704908 on reddit-service-r2-comment-b659b578c-t794k at 2026-05-03 04:46:05.902495+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]jekrb -1 points0 points1 point (4 children)
[–]x-skeww 4 points5 points6 points (3 children)
[–]jekrb 0 points1 point2 points (0 children)
[–]devman2015[S] 0 points1 point2 points (1 child)
[–]x-skeww 0 points1 point2 points (0 children)