JavaScript Methods Reference

Extensive reference for JS Array, String, Object, Number, Math, Date, JSON, RegExp, and Global methods

map()

Transform array elements

Syntax: array.map(callback)

Example: [1,2,3].map(x => x*2) // [2,4,6]

filter()

Filter array elements

Syntax: array.filter(callback)

Example: [1,2,3].filter(x => x>1) // [2,3]

reduce()

Reduce to a single value

Syntax: array.reduce(callback, initialValue)

Example: [1,2,3].reduce((a,b)=>a+b,0) // 6

find()

Find first matching element

Syntax: array.find(callback)

Example: [1,2,3].find(x=>x>1) // 2

includes()

Check if element exists

Syntax: array.includes(element)

Example: [1,2,3].includes(2) // true

sort()

Sort elements

Syntax: array.sort((a,b)=>a-b)

Example: [3,1,2].sort() // [1,2,3]

forEach()

Iterate over elements

Syntax: array.forEach(callback)

Example: [1,2,3].forEach(x=>console.log(x))

Date.now()

Current timestamp

Syntax: Date.now()

Example: Date.now() // 1690000000000

new Date()

Create date object

Syntax: new Date()

Example: new Date() // Thu Oct 31 2025 ...

console.log()

Print to console

Syntax: console.log(value)

Example: console.log("Hello")

alert()

Show alert

Syntax: alert(message)

Example: alert("Hi")

JSON.parse()

Parse JSON string

Syntax: JSON.parse(string)

Example: JSON.parse("{\"a\":1}") // {a:1}

JSON.stringify()

Convert object to JSON

Syntax: JSON.stringify(obj)

Example: JSON.stringify({a:1}) // "{"a":1}"

Math.random()

Generate random number 0-1

Syntax: Math.random()

Example: Math.random() // 0.12345

Math.floor()

Round down

Syntax: Math.floor(value)

Example: Math.floor(3.7) // 3

Math.ceil()

Round up

Syntax: Math.ceil(value)

Example: Math.ceil(3.2) // 4

Math.round()

Round to nearest integer

Syntax: Math.round(value)

Example: Math.round(3.5) // 4

parseInt()

Parse string to integer

Syntax: parseInt(string, radix)

Example: parseInt("10",10) // 10

parseFloat()

Parse string to float

Syntax: parseFloat(string)

Example: parseFloat("3.14") // 3.14

isNaN()

Check if value is NaN

Syntax: isNaN(value)

Example: isNaN("abc") // true

Object.keys()

Get object keys

Syntax: Object.keys(obj)

Example: Object.keys({a:1,b:2}) // ["a","b"]

Object.values()

Get object values

Syntax: Object.values(obj)

Example: Object.values({a:1,b:2}) // [1,2]

Object.entries()

Get key-value pairs

Syntax: Object.entries(obj)

Example: Object.entries({a:1,b:2}) // [["a",1],["b",2]]

RegExp.test()

Test regex pattern

Syntax: /pattern/.test(string)

Example: /hello/.test("hello world") // true

String.match()

Match regex in string

Syntax: string.match(regex)

Example: "abc123".match(/d+/) // ["123"]

slice()

Extract substring

Syntax: string.slice(start,end)

Example: "hello".slice(0,3) // "hel"

split()

Split string into array

Syntax: string.split(separator)

Example: "a-b-c".split("-") // ["a","b","c"]

replace()

Replace substring

Syntax: string.replace(search,replace)

Example: "hello".replace("h","H") // "Hello"

toUpperCase()

Convert to uppercase

Syntax: string.toUpperCase()

Example: "hello".toUpperCase() // "HELLO"

toLowerCase()

Convert to lowercase

Syntax: string.toLowerCase()

Example: "HELLO".toLowerCase() // "hello"