JavaScript quick reference

Everyday array, string and object methods on one page.

MethodPurpose
arr.push(x) / arr.pop()Add to / remove from the end
arr.map(fn)A new array of transformed items
arr.filter(fn)A new array of matching items
arr.find(fn)The first match
arr.includes(x)Whether it is present
arr.reduce(fn, start)Combine into one value
arr.sort((a, b) => a - b)Sort numbers. Without this, it sorts as text
s.trim() / s.split(",")Tidy spaces / break into an array
s.includes(x) / s.slice(a, b)Search / take a part
Object.keys(o)The property names
JSON.stringify / JSON.parseTo and from JSON text
Number(x) / String(x)Convert a value
โ† Errors and debuggingJavaScript learning path โ†’