← All 195 books javascript, one method per page
One method per page

javascript, one method per page

Twenty-four lessons on the Array methods JavaScript beginners actually meet: map, filter, flatMap, concat; find, findIndex, includes, indexOf; some, every, reduce, at; push, pop, shift, unshift; slice, splice, join, forEach; sort, reverse, fill, one honest hour; every method meaning traced to this box's cached MDN pages, and every returned value read whole from a twenty-four line array-method sweep node v26.7.0 ran on this box on the third of December, 2026, one call, one return and one mutate check per line, nothing typed from memory.


Steve Hodgkiss 7 lessons

One method, one page, one honest capture. That is the shape of this book.

javascript, one method per page

Twenty-four lessons on the Array methods JavaScript beginners actually meet: map, filter, flatMap, concat; find, findIndex, includes, indexOf; some, every, reduce, at; push, pop, shift, unshift; slice, splice, join, forEach; sort, reverse, fill, one honest hour; every method meaning traced to this box's cached MDN pages, and every returned value read whole from a twenty-four line array-method sweep node v26.7.0 ran on this box on the third of December, 2026, one call, one return and one mutate check per line, nothing typed from memory.


Set in Space Grotesk, Inter and JetBrains Mono (SIL Open Font License).

An honest book about its demo: node v26.7.0 on the machine that built this book ran a twenty-four line array-method sweep on 2026-12-03 (UTC), one call text, one returned value, a before and after mutate check and one surprise case per method, each capture kept whole. The sweep set no page, opened no port and started no server; the values live in /root/.hermes/cache/web/slot195park/javascript_demo195.txt, and no value was typed from memory. JSON.stringify prints NaN as null, so the includes capture is string-annotated in the file and is quoted exactly as the file states it. All method meaning traces to the 24 cached rendered MDN Array-method pages (developer.mozilla.org, fetched 2026-12-04 with STATUS 200 and size headers recorded). The map-versus-forEach question and the beginner-frustration framing are mined from public beginner-thread titles, used as questions only, never as facts. No facts from vendor blogs, search-engine snippets or books. Independent, not affiliated with Mozilla, MDN or TC39.

Your purchase is for personal use only. You do not have redistribution rights: please do not share, resell, or republish this book or its pages.

© 2026 Steve Hodgkiss. All rights reserved. Personal use only; no redistribution rights.

Edition 1.0 · stevehodgkiss.net

Contents

Contents


Part 1 · Build new arrays
map4
Part 2 · Find things
find5
Part 3 · Ask and fold
some6
Part 4 · Change the original
push7
Part 5 · Cut, count, join
slice8
Part 6 · Order and the honest hour9
sort10
one honest hour11

Per the MDN map page, The map() method of Array instances creates a new array populated with the results of calling a provided function on every element in the calling array; A new array with each element being the result of the callback function; It is not invoked for empty slots in sparse arrays. Per a real capture on the build machine (2026-12-03), call: nums.map(x => x * 2); returns: [6,2,8,2,10,18,4,12]; input_before: [3,1,4,1,5,9,2,6]; input_after: [3,1,4,1,5,9,2,6]; mutates: false. Per this book's plan, map opens the part that builds rows: every later page judges a method by what it builds or what it changes.

javascript companion · No. 01
the transformer

map

a new array, same length, new values

one callback, one arrow per slot, one new row outinput3141592662821018412one arrow per slot: a new array, same lengththe hole kept:[2,null,6]nums.map(x => x * 2)returns[6,2,8,2,10,18,4,12]falsemutatescaptured: every slot answered and a new row came back; the original came back whole

MDN names it plainly: map creates a new array populated with the results of calling a provided function on every element in the calling array.

Captured: nums.map(x => x * 2) returned [6,2,8,2,10,18,4,12] from [3,1,4,1,5,9,2,6], and the mutates check read false. The trap is the hole: It is not invoked for empty slots in sparse arrays, so the callback never ran on one.

A row built slot by slot: same length, new values, original whole.

SPEND ONE HONEST HOUR

This week, map one small array to its doubles in the console and log the original after.

Per the MDN find page, The find() method of Array instances returns the first element in the provided array that satisfies the provided testing function; If no values satisfy the testing function, undefined is returned; The first element in the array that satisfies the provided testing function; If you need to find all elements that satisfy the provided testing function, use filter(). Per a real capture on the build machine (2026-12-03), call: objs.find(o => o.n > 1); returns: {"n":2,"fruit":"banana"}; input_before: [{"n":2,"fruit":"banana"},{"n":1,"fruit":"apple"},{"n":3,"fruit":"fig"}]; input_after: [{"n":2,"fruit":"banana"},{"n":1,"fruit":"apple"},{"n":3,"fruit":"fig"}]; mutates: false. Per this book's plan, find opens the finding part with the question the threads ask first: which one do I actually need here.

javascript companion · No. 02
the first match

find

one element or undefined

the first match wins, and the search stops therebananaapplefign:2n:1n:3{"n":2,"fruit":"banana"}the first element onlyno match returns undefinedobjs.find(o => o.n > 1)returns{"n":2,"fruit":"banana"}falsemutatescaptured: one element out of three; the first that satisfied the test

find answers with an element: it returns the first element in the provided array that satisfies the provided testing function, and If no values satisfy the testing function, undefined is returned.

Captured: objs.find(o => o.n > 1) returned {"n":2,"fruit":"banana"} and stopped at the first. When the list is the point: If you need to find all elements that satisfy the provided testing function, use filter().

The first match or nothing: one element or undefined, never a list.

SPEND ONE HONEST HOUR

This week, find the first object past a threshold and log exactly what came back.

Per the MDN some page, The some() method of Array instances returns true if it finds an element in the array that satisfies the provided testing function. Otherwise, it returns false; for an empty array, it returns false for any condition; false unless callbackFn returns a truthy value for an array element, in which case true is immediately returned. Per the beginner threads digest, what is the difference between both. Per a real capture on the build machine (2026-12-03), call: nums.some(x => x > 8); returns: true; input_before: [3,1,4,1,5,9,2,6]; input_after: [3,1,4,1,5,9,2,6]; mutates: false. Per this book's plan, some opens the ask part: one pass ends the question.

javascript companion · No. 03
the any-check

some

true if any one passes

any one slot passing is enough: true comes back early31415926truefalsenums.some(x => x > 8)returnstruefalsemutatesempty array is falsecaptured: the ninth alone passed; an empty array never passes

some asks any: it returns true if it finds an element in the array that satisfies the provided testing function. Otherwise, it returns false.

Captured: nums.some(x => x > 8) returned true on the ninth alone, original untouched. The empty case is the trap: for an empty array, it returns false for any condition. The threads still ask the pair: what is the difference between both, a question, never a fact.

One pass is enough: any, not all.

SPEND ONE HONEST HOUR

This week, ask some about a condition only one slot can meet.

Per the MDN push page, The push() method of Array instances adds the specified elements to the end of an array and returns the new length of the array; The new length property of the object upon which the method was called. Per a real capture on the build machine (2026-12-03), call: words.push('fig'); returns: 5; input_before: ["fig","date","apple","banana"]; input_after: ["fig","date","apple","banana","fig"]; mutates: true. Per this book's plan, push opens the mutate part: the end door, and the first receipt that is not the array.

javascript companion · No. 04
the end door

push

add at the end, return the length

the end door opens: one slot longer, the length is the receiptfigdateapplebananafigdateapplebananafigthe return is the new length, not the elementwords.push('fig')returns5truemutatescaptured: four slots became five; the receipt is a number

push opens the end: it adds the specified elements to the end of an array and returns the new length of the array.

Captured: words.push('fig') grew ["fig","date","apple","banana"] to five slots and returned 5, the mutates check reading true. The beginner sting: returns the NEW length, not the element.

A mutation with a receipt: the length comes back, not the array.

SPEND ONE HONEST HOUR

This week, push one element and log the return before the array.

Per the MDN slice page, The slice() method of Array instances returns a shallow copy of a portion of an array into a new array object selected from start to end; The original array will not be modified; A new array containing the extracted elements; negative indices are counted from the end of the array. Per a real capture on the build machine (2026-12-03), call: nums.slice(2, 5); returns: [4,1,5]; input_before: [3,1,4,1,5,9,2,6]; input_after: [3,1,4,1,5,9,2,6]; mutates: false. Per this book's plan, slice opens the tools part with the honest cutter: a range copied, the original whole.

javascript companion · No. 05
the honest cutter

slice

copy a range, keep the original

a range copied out, the original never touched31415926end not included415[9,2,6]the tail, minus threenums.slice(2, 5)returns[4,1,5]falsemutatescaptured: slots two to four copied whole; the original row stayed

slice copies a range: it returns a shallow copy of a portion of an array into a new array object selected from start to end, the end not included, and The original array will not be modified.

Captured: nums.slice(2, 5) copied [4,1,5] out of slots two to four. The trick: negative index counts from the end, so minus three read [9,2,6].

The cutter that never cuts: a range out, the original whole.

SPEND ONE HONEST HOUR

This week, slice a range and log the original to prove it stayed whole.

Part 6 of 6
sort, reverse, fill, one honest hour
6

Order and the honest hour

Per the MDN sort page, The sort() method of Array instances sorts the elements of an array in place and returns the reference to the same array, now sorted; The default sort order is ascending, built upon converting the elements into strings. Per the MDN reverse page, the array is reversed in place. Per the MDN fill page, The fill() method of Array instances changes all elements within a range of indices in an array to a static value. Per a real capture on the build machine (2026-12-03), call: nums.slice().sort(); returns: [1,1,2,3,4,5,6,9]; call: words.reverse(); mutates: true; call: nums.fill(0, 2); returns: [3,1,0,0,0,0,0,0]. Per this book's plan, order closes the book: two mutators and a painter, then the closer that asks for an hour of the reader's own, one method per goal, no capture of ours.


In this part
  1. 01sort
  2. 02one honest hour

Per the MDN sort page, The sort() method of Array instances sorts the elements of an array in place and returns the reference to the same array, now sorted; The default sort order is ascending, built upon converting the elements into strings; In a numeric sort, 9 comes before 80, but because numbers are converted to strings, "80" comes before "9" in the Unicode order; The reference to the original array, now sorted. Per the beginner threads digest, does it create and return a new array, or does it modify the original. Per a real capture on the build machine (2026-12-03), call: nums.slice().sort(); returns: [1,1,2,3,4,5,6,9]; surprise.key: default sort is LEXICOGRAPHIC on strings; call: nums.sort((x, y) => x - y); mutates: true. Per this book's plan, sort opens the order part with the two-mouthed arranger: default strings, comparator numbers.

javascript companion · No. 06
the arranger

sort

in place, strings by default

the order changes in place: strings by default, numbers by comparator3141592611234569truenums.slice().sort()[1,10,2]the default order is lexicographicnums.sort((x, y) => x - y)returns[1,1,2,3,4,5,6,9]truemutatescaptured: sorted in place, twice; the default sort reads strings

sort arranges in place: it sorts the elements of an array in place and returns the reference to the same array, now sorted.

Captured twice: nums.slice().sort() returned [1,1,2,3,4,5,6,9], its own surprise reads [1,10,2], default sort is LEXICOGRAPHIC on strings. With nums.sort((x, y) => x - y) the numbers came back right: sort MUTATES the original.

Two mouths: strings by default, numbers need a comparator.

SPEND ONE HONEST HOUR

This week, sort an array holding a ten and watch the default lie.

Per this book's plan, the closer labels itself: one honest hour on your own console, one small array, one method per goal without searching, then the mutate-vs-copy check; this book ran twenty-four such captures on its own machine, and the hour asks for nothing more.

javascript companion · No. 07
the closer

one honest hour

your console, one method at a time

one array of your own, one method per goalconsoletype one small arraypick one method per goalread what came backthen check the mutate linethis book's plan:open your own console,no search, no framework,one method per goal,the hour is yoursno project, no prices, no capture: the hour closes one method at a time

Nothing new for once, a plan. Per this book's plan: open your own console, type one small array, and pick one method per goal without searching. Build a row, find a thing, ask a question, change the original, cut a piece, order it.

Then check the two honest halves this book kept: the method meaning against its MDN page, and the returned value against a whole captured line. If the mutates check surprises you, the page that owns the method has the answer.

One method, one page, one honest capture: the hour is yours now.

SPEND ONE HONEST HOUR

This week, spend sixty honest minutes with a console open: one small array, one method per goal.

Index

Index


find5
map4
one honest hour11
push7
slice8
some6
sort10