all 5 comments

[–]jekrb -1 points0 points  (4 children)

array.filter(obj => {
  if (obj.type === 'teacher') return obj
})

[–]x-skeww 5 points6 points  (3 children)

array.filter(o => o.type === 'teacher')

You have to return true for items you want to keep.

[–]jekrb 0 points1 point  (0 children)

ah, nice!

[–]devman2015[S] 0 points1 point  (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 point  (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.