Source code for the article TypeScript - How to Find Element in Array.
- TypeScript 7.0.2
- Node.js 22 or newer
npm install
npm startnpm start compiles the project and prints every value shown in the comments of the article's snippets.
| File | Article section |
|---|---|
src/00-quick-reference.ts |
Snippet with all search methods at the top of the article |
src/01-find.ts |
1. find() by property, early stop |
src/02-undefined.ts |
2. Handling the T | undefined result |
src/03-narrowing.ts |
3. Narrowing a union type with find() |
src/04-find-index.ts |
4. findIndex() and replacing an element (in place and with with()) |
src/05-find-last.ts |
5. findLast() and findLastIndex() |
src/06-by-value.ts |
6. indexOf(), lastIndexOf(), includes(), NaN, literal-type arrays |
src/index.ts |
Runs every section in order |