Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
JAVASCRIPT DATA / CHAPTER 02 / Learn / LESSON 11
Tenth class. .find returns the first matching element, or undefined if none.
function findByCategory(items, category) { return items.find((item) => item.category === category); }
Looking up "rent" finds the object. A missing category → undefined (not [] and not an error). An empty array also returns undefined.
Common mistake: expecting [] instead of undefined; or using filter[0] without knowing the difference.
find stops at the first match or yields undefined.
DATA STANDBY
›