Array
Arrays power most real-world JavaScript data work. Mastering the
core methods and loops is essential for exams, interviews, and
everyday productivity. Use this Cheat-Sheet to refresh quickly.
Loops Search & Test
for (indexed) → Full control ( break / continue ) find(predicate) → First matching element or undefined
for (let i = 0; i < [Link]; i++) { const v =
[1,4,6].find(x => x > 3) // 4
arr[i]; }
for...of → Iterate values findIndex(predicate) → Index of first match or -1
for (const v of arr) { /* ... */ } [1,4,6].findIndex(x => x > 3) // 1
entries() → Index + value via for...of findLast(predicate) → Last matching element or undefined
for (const [i, v] of [Link]()) { /* ... */ } [1,4,6].findLast(x => x > 3) // 6
forEach(fn) → Side effects only; no early break findLastIndex(predicate) → Index of last match or -1
[Link](v => { /* ... */ }); [1,4,6].findLastIndex(x => x > 3) // 2
while → Loop while condition is true some(predicate) → Any element passes?
let i = 0; while (i < [Link]) { i++; } [1,2,3].some(x => x > 2) // true
do...while → Runs at least once every(predicate) → All elements pass?
let i = 0; do { i++; } while (i < [Link]); [2,4,6].every(x => x % 2 === 0) // true
for...in → Enumerable keys; avoid for arrays indexOf(value) / lastIndexOf(value) → Position or -1
for (const k in arr) { /* */ } ['a','b','a'].lastIndexOf('a') // 2
for await...of → Async iteration includes(value) → Presence check
for await (const v of stream) { /* ... */ } [1,2].includes(2) // true
Note the one array method or loop you find most useful in
your daily work, drop it below to make it stick.
Brought to you by Creators of the
Learn more at [Link]/javascript
Array
Arrays power most real-world JavaScript data work. Mastering the
core methods and loops is essential for exams, interviews, and
everyday productivity. Use this Cheat-Sheet to refresh quickly.
Loops Search & Test
for (indexed) → Full control ( break / continue ) find(predicate) → First matching element or undefined
for (let i = 0; i < [Link]; i++) { const v =
[1,4,6].find(x => x > 3) // 4
arr[i]; }
for...of → Iterate values findIndex(predicate) → Index of first match or -1
for (const v of arr) { /* ... */ } [1,4,6].findIndex(x => x > 3) // 1
entries() → Index + value via for...of findLast(predicate) → Last matching element or undefined
for (const [i, v] of [Link]()) { /* ... */ } [1,4,6].findLast(x => x > 3) // 6
forEach(fn) → Side effects only; no early break findLastIndex(predicate) → Index of last match or -1
[Link](v => { /* ... */ }); [1,4,6].findLastIndex(x => x > 3) // 2
while → Loop while condition is true some(predicate) → Any element passes?
let i = 0; while (i < [Link]) { i++; } [1,2,3].some(x => x > 2) // true
do...while → Runs at least once every(predicate) → All elements pass?
let i = 0; do { i++; } while (i < [Link]); [2,4,6].every(x => x % 2 === 0) // true
for...in → Enumerable keys; avoid for arrays indexOf(value) / lastIndexOf(value) → Position or -1
for (const k in arr) { /* */ } ['a','b','a'].lastIndexOf('a') // 2
for await...of → Async iteration includes(value) → Presence check
for await (const v of stream) { /* ... */ } [1,2].includes(2) // true
Note the one array method or loop you find most useful in
your daily work, drop it below to make it stick.
Brought to you by Creators of the
Learn more at [Link]/javascript