Reference · 143 entries
JavaScript Reference
The JavaScript reference: built-in array, string, object, Math, Number and JSON methods with syntax, the ECMAScript edition that added each, and examples you can run in your browser.
JavaScript (ES2026) Version history
JavaScript has no versions to install: features arrive in yearly ECMAScript editions (ES2015, ES2016, …) and browsers add them one by one. Each page shows the edition that introduced a feature, linked to the JavaScript version history. Examples run in your browser's own JavaScript engine; check browser support on MDN for features from the last year or two.
Array Methods
Every JavaScript array method, from at() to with(), with syntax, parameters and examples you can run. Shows which methods change the array and which return a copy.
| Name | Description |
|---|---|
array.at() | Return the element at an index, where negative indexes count from the end: arr.at(-1) is the last element. |
array.concat() | Return a new array that joins this array with other arrays or values. The original arrays are not changed. |
array.copyWithin() | Copy a slice of the array to another position in the same array, overwriting what's there. Changes the array in place. |
array.entries() | Return an iterator of [index, element] pairs, handy for looping with both the index and the value. |
array.every() | Return true if every element passes a test function. Stops at the first failure; an empty array returns true. |
array.fill() | Fill all or part of an array with a static value, changing it in place. Often used to create an array of defaults. |
array.filter() | Return a new array with only the elements that pass a test function. The original array is not changed. |
array.find() | Return the first element that passes a test function, or undefined if none does. |
array.findIndex() | Return the index of the first element that passes a test function, or -1 if none does. |
array.findLast() | Return the last element that passes a test function, searching from the end, or undefined if none does. |
array.findLastIndex() | Return the index of the last element that passes a test function, or -1 if none does. |
array.flat() | Return a new array with nested arrays flattened into it, one level deep by default or to a given depth. |
array.flatMap() | Map each element with a function, then flatten the result one level. Useful when one element becomes several. |
array.forEach() | Call a function once for each element. It returns undefined, so use map() when you need a new array. |
array.includes() | Return true if the array contains a value, using SameValueZero equality (so it finds NaN, unlike indexOf). |
array.indexOf() | Return the first index at which a value is found (using ===), or -1 if it isn't in the array. |
array.join() | Join all elements into one string, separated by commas or by a separator you choose. |
array.keys() | Return an iterator of the array's indexes, including indexes of empty slots. |
array.lastIndexOf() | Return the last index at which a value is found (using ===), searching backwards, or -1 if it isn't there. |
array.length | The number of elements in the array. Setting it shortens or extends the array. |
array.map() | Return a new array with the results of calling a function on every element. The original array is unchanged. |
array.pop() | Remove the last element from the array and return it. Changes the array; returns undefined if it is empty. |
array.push() | Add one or more elements to the end of the array and return the new length. Changes the array in place. |
array.reduce() | Reduce the array to a single value by running a reducer function on each element, carrying an accumulator along. |
array.reduceRight() | Like reduce(), but processes the array from the last element to the first. |
array.reverse() | Reverse the array in place and return it. Use toReversed() to get a reversed copy instead. |
array.shift() | Remove the first element of the array and return it, moving the other elements down. Returns undefined if empty. |
array.slice() | Return a shallow copy of part of the array, from start up to (not including) end. The original is not changed. |
array.some() | Return true if at least one element passes a test function. Stops at the first match; an empty array returns false. |
array.sort() | Sort the array in place and return it. Without a compare function elements are sorted as strings, so numbers need one. |
String Methods
Every JavaScript string method, from at() to trimEnd(), with syntax, parameters, the ECMAScript edition that added it, and examples you can run.
| Name | Description |
|---|---|
string.at() | Return the character at an index, where negative indexes count from the end: str.at(-1) is the last character. |
string.charAt() | Return the character at a given index as a new string, or an empty string if the index is out of range. |
string.charCodeAt() | Return the UTF-16 code unit (0 to 65535) at an index. For emoji and other astral characters use codePointAt(). |
string.codePointAt() | Return the full Unicode code point at an index, correctly handling emoji and other characters outside the BMP. |
string.concat() | Join one or more strings to the end of this string and return the result. The + operator and template literals are more common. |
string.endsWith() | Return true if the string ends with the given text. Case-sensitive; an optional length treats the string as shorter. |
string.includes() | Return true if the string contains the given text anywhere. Case-sensitive. |
string.indexOf() | Return the index of the first occurrence of some text, or -1 if it isn't found. |
string.isWellFormed() | Return true if the string has no lone surrogates, i.e. it can be safely encoded as UTF-8. |
string.lastIndexOf() | Return the index of the last occurrence of some text, searching backwards, or -1 if it isn't found. |
string.length | The number of UTF-16 code units in the string, which is more than the number of characters for emoji. |
string.localeCompare() | Compare two strings using language rules; returns a negative number, 0 or a positive number. Use it to sort names. |
string.match() | Match the string against a regular expression and return the matches (all of them with the g flag) or null. |
string.matchAll() | Return an iterator of every regular-expression match, including capture groups. The regex must have the g flag. |
string.normalize() | Return the Unicode normalization form of a string so visually identical text compares equal (NFC, NFD, NFKC, NFKD). |
string.padEnd() | Pad the end of a string with another string until it reaches a target length. Useful for aligned text columns. |
string.padStart() | Pad the start of a string until it reaches a target length, for example zero-padding numbers like 007. |
string.repeat() | Return a new string made of this string repeated a given number of times, for example to build separators or padding. |
string.replace() | Replace the first match of a string or regex (every match with the g flag) with new text or a function's result. |
string.replaceAll() | Replace every occurrence of a string (or regex with the g flag) with new text, without writing a regex. |
string.search() | Return the index of the first regular-expression match, or -1 if there is none. |
string.slice() | Extract part of a string between two indexes; negative indexes count from the end. |
string.split() | Split a string into an array of substrings at each separator (a string or regex), with an optional limit. |
string.startsWith() | Return true if the string begins with the given text. Case-sensitive; an optional position starts the check later. |
string.substring() | Return the part of a string between two indexes. Unlike slice(), negative values become 0 and swapped arguments are reordered. |
string.toLowerCase() | Return the string converted to lowercase. Use it for case-insensitive comparisons. |
string.toLocaleLowerCase() | Convert to lowercase using a language's rules, which matters for languages like Turkish. |
string.toLocaleUpperCase() | Convert to uppercase using a language's rules, for example Turkish or German special cases. |
string.toUpperCase() | Return the string converted to uppercase letters. Use toLocaleUpperCase() for language-specific rules. |
string.toWellFormed() | Return a copy where lone surrogates are replaced with U+FFFD, so the string can be encoded safely. |
Object Methods
The static Object methods: keys(), entries(), assign(), freeze(), groupBy() and more, with the ECMAScript edition that added each and runnable examples.
| Name | Description |
|---|---|
Object.assign() | Copy all own enumerable properties from one or more source objects into a target object, and return the target. |
Object.create() | Create a new object with the given prototype (or null for an object with no inherited properties at all). |
Object.defineProperty() | Add or change one property with full control over whether it is writable, enumerable and configurable, or define a getter. |
Object.defineProperties() | Add or change several properties at once using property descriptors, each with its own writable and enumerable flags. |
Object.entries() | Return an array of an object's own enumerable [key, value] pairs, ready for for…of loops or array methods. |
Object.freeze() | Make an object immutable: no properties can be added, removed or changed. The freeze is shallow. |
Object.fromEntries() | Build an object from an iterable of [key, value] pairs, such as an array or a Map. The opposite of Object.entries(). |
Object.getOwnPropertyDescriptor() | Return the descriptor (value, writable, enumerable, configurable or get/set) of one own property. |
Object.getOwnPropertyNames() | Return all own string property names, including non-enumerable ones that Object.keys() skips. |
Object.getPrototypeOf() | Return the prototype of an object: the object it inherits methods and properties from, or null. |
Object.groupBy() | Group the items of an iterable into an object whose keys come from a callback, e.g. orders grouped by status. |
Object.hasOwn() | Return true if an object has a property of its own (not inherited). The safer replacement for hasOwnProperty(). |
Object.is() | Compare two values like === but treat NaN as equal to NaN and +0 as different from -0. |
Object.isFrozen() | Return true if an object is frozen: no properties can be added, removed or changed. |
Object.isSealed() | Return true if an object is sealed: properties can't be added or removed, but existing ones may still change. |
Object.keys() | Return an array of an object's own enumerable property names, in insertion order (integer keys first). |
Object.seal() | Prevent adding or removing properties while still allowing existing properties to be changed. |
Object.setPrototypeOf() | Change the prototype of an existing object. It is slow in most engines; prefer Object.create() or classes. |
Object.values() | Return an array of an object's own enumerable property values, in the same order as Object.keys(). |
Math Methods and Constants
Every commonly used Math function and constant, from abs() and round() to random() and sumPrecise(), with examples for rounding, ranges, geometry and logarithms.
| Name | Description |
|---|---|
Math.abs() | Return the absolute value of a number: its distance from zero, so Math.abs(-5) is 5. |
Math.ceil() | Round a number up to the next integer: Math.ceil(4.1) is 5 and Math.ceil(-4.1) is -4. |
Math.floor() | Round a number down to the integer below it: Math.floor(4.9) is 4 and Math.floor(-4.1) is -5. |
Math.round() | Round a number to the nearest integer; halves round up towards +Infinity, so Math.round(-2.5) is -2. |
Math.trunc() | Remove the fractional part of a number, rounding towards zero: Math.trunc(-4.7) is -4. |
Math.sign() | Return 1, -1 or 0 depending on whether a number is positive, negative or zero. |
Math.max() | Return the largest of the given numbers. Use the spread syntax to find the largest value in an array. |
Math.min() | Return the smallest of the given numbers. Use spread to find the smallest value in an array. |
Math.pow() | Return a base raised to an exponent. The ** operator does the same: Math.pow(2, 10) equals 2 ** 10. |
Math.sqrt() | Return the square root of a number, or NaN for negative numbers. Use it for distances and the Pythagorean theorem. |
Math.cbrt() | Return the cube root of a number; unlike Math.pow(x, 1/3) it works for negative numbers. |
Math.hypot() | Return the square root of the sum of squares of its arguments, e.g. the length of a vector or a diagonal. |
Math.random() | Return a pseudo-random number from 0 (inclusive) up to 1 (exclusive). Not suitable for security; use crypto for that. |
Math.log() | Return the natural logarithm (base e) of a number; divide by Math.log(base) to get a logarithm in any base. |
Math.log10() | Return the base-10 logarithm of a number, e.g. to count digits or work with decibels. |
Math.log2() | Return the base-2 logarithm of a number, e.g. how many bits or how many halvings are needed. |
Math.exp() | Return e (about 2.718) raised to the given power, used for exponential growth, decay and probability formulas. |
Math.sin() | Return the sine of an angle given in radians. Convert degrees with deg * Math.PI / 180 first. |
Math.cos() | Return the cosine of an angle given in radians. Convert degrees with deg * Math.PI / 180 first. |
Math.atan2() | Return the angle in radians between the positive x axis and the point (x, y). Note the argument order: y first. |
Math.PI | The ratio of a circle's circumference to its diameter, approximately 3.14159. |
Math.E | Euler's number, the base of natural logarithms, approximately 2.71828. |
Math.sumPrecise() | Add up an iterable of numbers with full precision, avoiding the rounding errors of repeated + additions. |
Number Methods and Properties
Number methods and constants: isInteger(), isNaN(), parseInt(), toFixed(), toLocaleString(), MAX_SAFE_INTEGER and EPSILON, with examples you can run.
| Name | Description |
|---|---|
Number.isInteger() | Return true if a value is a number with no fractional part. Strings aren't converted, so Number.isInteger("5") is false. |
Number.isSafeInteger() | Return true if a value is an integer that can be represented exactly, between -(2^53 - 1) and 2^53 - 1. |
Number.isFinite() | Return true if a value is a finite number. Unlike the global isFinite(), it doesn't convert strings. |
Number.isNaN() | Return true only if a value is the number NaN. Unlike the global isNaN(), it doesn't convert strings first. |
Number.parseFloat() | Parse a decimal number from the start of a string, ignoring trailing text. Same as the global parseFloat(). |
Number.parseInt() | Parse an integer from the start of a string in a given base (radix). Always pass the radix, usually 10. |
Number.MAX_SAFE_INTEGER | The largest integer JavaScript numbers can represent exactly: 2^53 - 1, or 9,007,199,254,740,991. |
Number.EPSILON | The smallest difference between 1 and the next representable number, used as a tolerance when comparing floats. |
number.toFixed() | Format a number with a fixed number of decimal places, returned as a string. Rounds, but floating-point quirks apply. |
number.toPrecision() | Format a number to a given number of significant digits, using exponential notation when needed. |
number.toString() | Convert a number to a string, optionally in another base such as 2 (binary) or 16 (hexadecimal). |
number.toLocaleString() | Format a number for display using locale rules: thousands separators, decimals, currency and percentages. |
JSON and Global Functions
JSON.parse(), JSON.stringify() and global functions such as parseInt(), isNaN(), encodeURIComponent() and structuredClone(), with common mistakes and examples.
| Name | Description |
|---|---|
JSON.parse() | Turn a JSON string into a JavaScript value. Throws SyntaxError on invalid JSON; an optional reviver transforms values. |
JSON.stringify() | Convert a JavaScript value to a JSON string, optionally filtering keys and pretty-printing with indentation. |
parseInt() | Parse an integer from the start of a string in a given base. Always pass the radix, e.g. parseInt("08", 10). |
parseFloat() | Parse a decimal number from the start of a string, stopping at the first character that can't be part of it. |
isNaN() | Return true if a value is NaN after converting it to a number, so isNaN("hello") is true. Prefer Number.isNaN(). |
isFinite() | Return true if a value is a finite number after converting it to a number. Prefer Number.isFinite() for strict checks. |
encodeURIComponent() | Encode a string for use as one part of a URL (a query value or path segment), escaping &, =, ?, / and spaces. |
decodeURIComponent() | Decode a URL component encoded by encodeURIComponent(), turning %20-style escapes back into characters. |
encodeURI() | Encode a complete URL, leaving characters with special meaning in URLs (like :, /, ? and &) untouched. |
decodeURI() | Decode a full URL encoded by encodeURI(), keeping escape sequences that represent reserved URL characters. |
structuredClone() | Create a deep copy of a value, including nested objects, arrays, Dates, Maps and Sets. Functions can't be cloned. |