710 B
Executable File
710 B
Executable File
Array find and Arrow Functions
Array.prototype.find returns the first element that matches a condition.
Example
const parts = [
{ type: 'year', value: '2026' },
{ type: 'month', value: '03' },
{ type: 'day', value: '24' },
];
const yearPart = parts.find((part) => part.type === 'year');
console.log(yearPart); // { type: 'year', value: '2026' }
Arrow Function Syntax
(part) => part.type === 'year'
(part): parameter.=>: arrow token.part.type === 'year': expression result (trueorfalse).
If no item matches, find returns undefined.
Python Comparison
Similar to:
year_part = next((p for p in parts if p['type'] == 'year'), None)