String
Return Type: String
| Method | Description | Example | Result |
|---|---|---|---|
charAt(index) | Character at position (empty string if out of range). | 'Hello'.charAt(1) | 'e' |
concat(...strings) | Concatenate strings. | 'Hello'.concat(' ', 'World') | 'Hello World' |
slice(start, end?) | Extract substring by indices (end not included). | 'Hello'.slice(1, 4) | 'ell' |
substring(start, end?) | Extract substring; swaps args if start > end. | 'Hello'.substring(1, 4) | 'ell' |
toUpperCase() | Uppercase copy. | 'hi'.toUpperCase() | 'HI' |
toLowerCase() | Lowercase copy. | 'HI'.toLowerCase() | 'hi' |
trim() | Remove leading/trailing whitespace. | ' hi '.trim() | 'hi' |
trimStart(), trimEnd() | Remove whitespace at start or end. | ' hi'.trimStart() | 'hi' |
padStart(targetLength, padString?) | Pad at start to reach length. | '5'.padStart(3, '0') | '005' |
padEnd(targetLength, padString?) | Pad at end to reach length. | '5'.padEnd(3, '0') | '500' |
repeat(count) | Repeat string count times. | 'ab'.repeat(3) | 'ababab' |
replace(searchValue, replaceValue) | Replace first match (string or regex). | 'hi hi'.replace('hi','yo') | 'yo hi' |
replaceAll(searchValue, replaceValue) | Replace all matches. | 'hi hi'.replaceAll('hi','yo') | 'yo yo' |
normalize(form?) | Unicode normalization (NFC, NFD, NFKC,NFKD). | 'é'.normalize('NFD') | 'é' |
toString(), valueOf() | Primitive string value. | new String('x').toString() | 'x' |
Return Type: Number
| Method | Description | Example | Result |
|---|---|---|---|
parseInt(string) | Parses a string and returns an integer. | parseInt('77') | 77 |
parseFloat(string) | Parses a string and returns a floating point number. | parseFloat('4.567') | 4.567 |
charCodeAt(index) | UTF‑16 code unit at position. | 'ABC'.charCodeAt(0) | 65 |
indexOf(searchValue, fromIndex?) | First index of substring (or -1). | 'Hello'.indexOf('l') | 2 |
lastIndexOf(searchValue, fromIndex?) | Last index of substring (or -1). | 'Hello'.lastIndexOf('l') | 3 |
localeCompare(other, locales?, options?) | Compares strings using locale rules. | 'a'.localeCompare('b') | -1 (read notes) |
search(regexp) | Index of first regex match (or -1). | 'abc'.search(/b/) | 1 |
Return Type: Boolean
| Method | Description | Example | Result |
|---|---|---|---|
includes(substring, fromIndex?) | Substring presence. | 'Hello'.includes('ell') | true |
startsWith(prefix, position?) | Check starting substring. | 'Hello'.startsWith('He') | true |
endsWith(suffix, length?) | Check ending substring. | 'Hello'.endsWith('lo') | true |
Return Type: Array
| Method | Description | Example | Result |
|---|---|---|---|
split(separator, limit?) | Split into array of substrings. | 'a,b,c'.split(',') | ['a','b','c'] |
Return Type: Iterator
| Method | Description | Example | Result |
|---|---|---|---|
matchAll(regexp) | Returns an iterator of all regex matches. | Array.from('test'.matchAll(/t/g)) | [['t'],['t']] (after Array.from) |
Return Type: Array ornull
| Method | Description | Example | Result |
|---|---|---|---|
match(regexp) | First regex match result array (or null if none). | 'abc'.match(/b/) | ['b', index:1, input:'abc', groups:undefined] (or null) |
Notes
- Most string methods are case-sensitive by default. To do case-insensitive checks, use regex with the
iflag or convert both strings to a common case withtoLowerCase()/toUpperCase(). String.prototype.at(index)can return a string orundefined(if out of range), so it is omitted from single-type tables.substr()is deprecated; preferslice()orsubstring().localeComparereturns different values depending on whether the reference value is before/after/equal to the compare value-1: if the reference value is before the compared value (i.e. 'a'.localeCompare('b'))0: if the reference is equal to the compared (i.e. 'b'.localeCompare('b'))1: if the reference is after the compared (i.e. 'c'.localeCompare('b'))
Array
Return Type: Boolean
| Method | Description | Example | Result | Callback Arguments |
|---|---|---|---|---|
every(callbackFn, thisArg?) | Checks if all elements pass the test. | [1, 2, 3].every(x => x > 0) | true |
|
some(callbackFn, thisArg?) | Checks if at least one element passes the test. | [1, 2, 3].some(x => x > 2) | true |
|
includes(valueToFind, fromIndex?) | Checks if the array contains a value. | [1, 2, 3].includes(2) | true | - |
Return Type: Number
| Method | Description | Example | Result | Callback Arguments |
|---|---|---|---|---|
indexOf(searchElement, fromIndex?) | Returns the first index of the element, or -1 if not found. | ['a', 'b', 'c'].indexOf('b') | 1 | - |
lastIndexOf(searchElement, fromIndex?) | Returns the last index of the element, or -1 if not found. | ['a', 'b', 'a'].lastIndexOf('a') | 2 | - |
findIndex(callbackFn, thisArg?) | Returns the index of the first element that satisfies the test, or -1. | [4, 6, 8].findIndex(x => x > 5) | 1 |
|
reduce(callbackFn, initialValue) | Reduce an array to a single value by applying a function to each element, accumulating the result. | [1,2].reduce((acc, curr) => acc + curr, 0) | 3 |
|
Return Type: String
| Method | Description | Example | Result |
|---|---|---|---|
join(separator?) | Joins all elements into a string. | ['a', 'b', 'c'].join('-') | 'a-b-c' |
toString() | Converts the array to a comma-separated string. | [1, 2, 3].toString() | '1,2,3' |
toLocaleString() | Converts array to a locale-sensitive string. | [1234.56].toLocaleString() | '1,234.56' (US locale) |
Return Type: Array
| Method | Description | Example | Result | Callback Arguments |
|---|---|---|---|---|
filter(callbackFn, thisArg?) | Creates a new array with elements that pass the test. | [1, 2, 3, 4].filter(x => x > 2) | [3, 4] |
|
map(callbackFn, thisArg?) | Creates a new array with results of calling a function on every element. | [1, 2, 3].map(x => x * 2) | [2, 4, 6] |
|
slice(start?, end?) | Returns a shallow copy of a portion of the array. | ['a', 'b', 'c'].slice(1) | ['b', 'c'] | - |
Return Type: Element
| Method | Description | Example | Result | Callback Arguments |
|---|---|---|---|---|
find(callbackFn, thisArg?) | Returns the first element that satisfies the test, or undefined. | [5, 12, 8].find(x => x > 10) | 12 |
|
pop() | Removes the last element and returns it. | let arr = [1, 2, 3]; arr.pop() | 3 | - |
shift() | Removes the first element and returns it. | let arr = [1, 2, 3]; arr.shift() | 1 | - |
Return Type: Number (Length)
| Method | Description | Example | Result |
|---|---|---|---|
push(...items) | Adds one or more elements to the end, returns new length. | let arr = [1]; arr.push(2, 3) | 3 |
unshift(...items) | Adds one or more elements to the start, returns new length. | let arr = [1]; arr.unshift(0) | 2 |
Return Type: Undefined (no return)
| Method | Description | Example | Result | Callback Arguments |
|---|---|---|---|---|
forEach(callbackFn) | Act on each element using the provided function. | [1, 2, 3].forEach((element) => console.log(element)); | 1 2 3 |
|
Notes
- A shallow copy creates a new object, but it doesn't duplicate nested objects; it copies references to them
- i.e. changes to the nested objects in the copy also affect the original
- Arrays in JavaScript are zero-indexed.
- Other methods (
map,filter,slice,concat) return a new array without changing the original.
Set
Return Type: Boolean
| Method | Description | Example | Result |
|---|---|---|---|
has(value) | Checks if the Set contains a value. | new Set([1, 2, 3]).has(2) | true |
delete(value) | Removes a value from the Set. Returns true if found and removed, otherwisefalse. | let s = new Set([1]); s.delete(1) | true |
Return Type: Number
| Method | Description | Example | Result |
|---|---|---|---|
size | Returns the number of elements in the Set. | new Set([1, 2, 3]).size | 3 |
Return Type: Set (itself) or undefined
| Method | Description | Example | Result | Callback Arguments |
|---|---|---|---|---|
add(value) | Adds a new value to the Set and returns the Set object. | let s = new Set(); s.add(1) | Set 1 | - |
clear() | Removes all elements from the Set and returns undefined. | let s = new Set([1, 2]); s.clear() | undefined | - |
forEach(callbackFn) | Act on each element using the provided function. | new Set([1, 2, 3]).forEach((element) => console.log(element)); | 1 2 3 |
|
Return Type: Iterator
| Method | Description | Example | Result |
|---|---|---|---|
values() | Returns a new Iterator object containing all values. | [...new Set([1, 2]).values()] | [1, 2] |
keys() | Alias for values() in Set. | [...new Set(['a', 'b']).keys()] | ['a', 'b'] |
entries() | Returns a new Iterator of [value, value] pairs. | [...new Set(['x', 'y']).entries()] | [['x', 'x'], ['y', 'y']] |
Notes
- Set objects store UNIQUE values of any type, whether primitive values or object references.
- The insertion order is preserved when iterating over a Set.
Set.prototype.sizeis a property, not a method.
Map
Return Type: Boolean
| Method | Description | Example | Result |
|---|---|---|---|
has(key) | Returns true if a Map contains the specified key. | new Map([[1, 'a']]).has(1) | true |
delete(key) | Removes a Map element by key and returns true if removed. | let m = new Map([[1,'a']]); m.delete(1) | true |
Return Type: Number
| Method | Description | Example | Result |
|---|---|---|---|
size | Returns the number of key/value pairs in the Map. | new Map([[1,'a'], [2,'b']]).size | 2 |
Return Type: Map (itself) or undefined
| Method | Description | Example | Result |
|---|---|---|---|
set(key, value) | Adds or updates an element with a specified key and value. | let m = new Map(); m.set(1,'a') | Map {1 => 'a' &125; |
clear() | Removes all Map elements. | let m = new Map([[1,'a']]); m.clear() | undefined |
Return Type: Iterator
| Method | Description | Example | Result | Callback Arguments |
|---|---|---|---|---|
keys() | Returns a new Iterator object containing the keys of the Map. | myMap = new Map([[1,'a'],[2,'b']]); myMap.keys(); | [1,2] | - |
values() | Returns a new Iterator object containing the values of the Map. | myMap = new Map([[1,'a'],[2,'b']]); myMap.values(); | ['a','b'] | - |
entries() | Returns a new Iterator object containing [key, value] pairs for each element. | myMap = new Map([[1,'a'],[2,'b']]); myMap.entries(); | [[1,'a'],[2,'b']] | - |
forEach(callback, thisArg?) | Calls a function for each key/value pair in the Map. | myMap = new Map([[1,'a']]); myMap.forEach((v,k) => console.log(k,v)) | logs: 1 'a' |
|
Notes
forEach(callback(value, key, map)): the key and value positions are flipped- Map keys can be of any value type, including objects and functions.
- Insertion order of keys is preserved during iteration.
- Use
forEachor the iterator methods (keys,values,entries) to traverse a Map. sizeis a property, not a method.
Object
Return Type: Boolean
| Method | Description | Example | Result |
|---|---|---|---|
hasOwnProperty(prop) | Checks if the object has the specified property as its own property. | ({ a: 1 }).hasOwnProperty('a') | true |
propertyIsEnumerable(prop) | Checks if a property is enumerable. | ({ a: 1 }).propertyIsEnumerable('a') | true |
Return Type: Array
| Method | Description | Example | Result |
|---|---|---|---|
Object.keys(obj) | Returns an array of the object's own enumerable property names. | Object.keys({ a: 1, b: 2 }) | ['a', 'b'] |
Object.values(obj) | Returns an array of the object's own enumerable property values. | Object.values({ a: 1, b: 2 }) | [1, 2] |
Object.entries(obj) | Returns an array of the object's own enumerable [key, value] pairs. | Object.entries({ a: 1 }) | [['a', 1]] |
Return Type: Object
| Method | Description | Example | Result |
|---|---|---|---|
Object.assign(target, ...sources) | Copies properties from source objects to a target object. | Object.assign({}, { a: 1 }, { b: 2 }) | { a: 1, b: 2 } |
Object.create(proto, propertiesObject?) | Creates a new object with the specified prototype object and properties. | Object.create({ a: 1 }) | Object with prototype { a: 1 } |
Object.fromEntries(iterable) | Returns a new object from an iterable of [key, value] pairs. | Object.fromEntries([['a', 1]]) | { a: 1 } |
Return Type: String or Primitive
| Method | Description | Example | Result |
|---|---|---|---|
toString() | Returns a string representation of the object. | ({ a: 1 }).toString() | '[object Object]' |
valueOf() | Returns the primitive value of the specified object. | ({ a: 1 }).valueOf() | { a: 1 } |
Notes
- Some Object methods are static (e.g.,
Object.keys), while others are instance methods (e.g.,toString).
JSON
Return Type: String
| Method | Description | Example | Result |
|---|---|---|---|
JSON.stringify(value, replacer?, space?) | Converts a JavaScript value to a JSON string. | JSON.stringify({ a: 1 }) | '{'a':1}' |
Return Type: Object
| Method | Description | Example | Result |
|---|---|---|---|
JSON.parse(text, reviver?) | Parses a JSON string and returns the corresponding JavaScript value. | JSON.parse('{'a':1}') | { a: 1 } |
Notes
- All JSON methods are static and are called on the
JSONobject. JSON.stringifycan take a replacer function/array to filter properties, and aspace argument to format the output.JSON.parsecan take a reviver function to transform values during parsing.- JSON only supports strings, numbers, booleans, null, arrays, and objects (no functions or
undefined).
Math
Return Type: Number
| Function | Description | Example | Result |
|---|---|---|---|
Math.abs(x) | Returns the absolute value of a number. | Math.abs(-5) | 5 |
Math.ceil(x) | Returns the smallest integer greater than or equal to a number. | Math.ceil(4.2) | 5 |
Math.floor(x) | Returns the largest integer less than or equal to a number. | Math.floor(4.8) | 4 |
Math.round(x) | Returns the value of a number rounded to the nearest integer. | Math.round(4.5) | 5 |
Math.max(...values) | Returns the largest of zero or more numbers. | Math.max(1, 3, 2) | 3 |
Math.min(...values) | Returns the smallest of zero or more numbers. | Math.min(1, 3, 2) | 1 |
Math.random() | Returns a pseudo-random number between 0 (inclusive) and 1 (exclusive). | Math.random() | 0.123... (varies) |
Math.sqrt(x) | Returns the positive square root of a number. | Math.sqrt(9) | 3 |
Math.pow(base, exponent) | Returns the base raised to the exponent power. | Math.pow(2, 3) | 8 |
Math.PI | Returns pi | Math.PI | 3.14... |
Return Type: Boolean
| Method | Description | Example | Result |
|---|---|---|---|
Number.isFinite(value) | Determines whether the passed value is a finite number. | Number.isFinite(10) | true |
Number.isNaN(value) | Determines whether the passed value is NaN. | Number.isNaN(NaN) | true |
Number.isInteger(value) | Determines whether the passed value is an integer. | Number.isInteger(4) | true |
Notes
- All
Mathmethods are static and must be called on theMathobject (e.g.,Math.sqrt(4)). Math.random()does not produce cryptographically secure numbers. Usecrypto.getRandomValues()for secure random numbers.- Some numeric checks like
isNaN()exist globally, butNumber.isNaN()is more reliable because it does not coerce values.