It's pronounced Diane. I do data architecture, operations, and backend development. In my spare time I maintain Massive.js, a data mapper for Node.js and PostgreSQL.
includes returns a boolean value but forEach does not (or rather, it returns undefined). So the result of the includes call is simply thrown away if you use forEach instead of some.
Two obvious improvements to the working method:
iterate restaurant.menuEntities with some as well, if it's possible that the result you're looking for is not in the very first one
use reduce instead of filter; if you search, there have been numerous guides posted here
Additionally, if you're retrieving the restaurant & menu records from a relational database you could short-circuit the whole thing by filtering in your query instead of in application logic.
Hahhaa for the menuEntities yeah I'll definitely have to use .some if there's more than one.. Thanks for the reminder & explanation, makes sense that the results of includes is thrown away with forEach
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
includes
returns a boolean value butforEach
does not (or rather, it returnsundefined
). So the result of theincludes
call is simply thrown away if you useforEach
instead ofsome
.Two obvious improvements to the working method:
restaurant.menuEntities
withsome
as well, if it's possible that the result you're looking for is not in the very first onereduce
instead offilter
; if you search, there have been numerous guides posted hereAdditionally, if you're retrieving the restaurant & menu records from a relational database you could short-circuit the whole thing by filtering in your query instead of in application logic.
Hahhaa for the menuEntities yeah I'll definitely have to use .some if there's more than one.. Thanks for the reminder & explanation, makes sense that the results of includes is thrown away with forEach