JavaScript Predefined Functions & Methods Cheat Sheet
1. String Methods
- length: Get string length
- charAt(index): Get character at index
- at(index): New way to get char (supports negative)
- charCodeAt(index): Unicode value of char
- slice(start, end): Extract substring
- substring(start, end): Similar to slice but no negatives
- substr(start, length): Legacy substring by length
- toUpperCase(): Uppercase
- toLowerCase(): Lowercase
- trim(): Remove spaces around
- split(separator): Convert string to array
- replace(old, new): Replace first match
- replaceAll(old, new): Replace all matches
- includes(substring): Check if exists
- startsWith(sub): Starts with?
- endsWith(sub): Ends with?
- repeat(n): Repeat string
- padStart(len, padStr): Pad from start
- padEnd(len, padStr): Pad from end
2. Array Methods
- length: Count elements
- push(item): Add at end
- pop(): Remove from end
- shift(): Remove from start
- unshift(item): Add at start
- concat(arr2): Merge arrays
- slice(start, end): Extract part
- splice(start, deleteCount, items...): Remove/add anywhere
- indexOf(value): First index of value
- lastIndexOf(value): Last index
- includes(value): Check existence
- join(separator): Join into string
- reverse(): Reverse array
- sort(compareFn): Sort array
- forEach(fn): Loop over items
- map(fn): Transform each item
- filter(fn): Keep matching items
- reduce(fn, initial): Accumulate value
- find(fn): First matching element
- findIndex(fn): Index of match
- some(fn): Any match?
- every(fn): All match?
- flat(depth): Flatten nested arrays
- flatMap(fn): Map + flatten
3. Number & Math Methods
- Number(): Convert to number
- parseInt(str): Integer from string
- parseFloat(str): Decimal from string
- isNaN(val): Check NaN
- isFinite(val): Check finite
- toFixed(n): Fixed decimal places
- Math.round(x): Round to nearest
- Math.floor(x): Round down
- Math.ceil(x): Round up
- Math.abs(x): Absolute value
- Math.max(a,b,...): Largest number
- Math.min(a,b,...): Smallest number
- Math.random(): Random 0-1
- Math.pow(a,b): Power
- Math.sqrt(x): Square root
- Math.trunc(x): Remove decimal
4. Object Methods
- Object.keys(obj): Keys as array
- Object.values(obj): Values as array
- Object.entries(obj): Key-value pairs
- Object.assign(target, source): Merge objects
- Object.freeze(obj): Lock object
- Object.seal(obj): No new props
- hasOwnProperty(key): Key exists?
5. Date Methods
- new Date(): Current date/time
- getFullYear(): Year
- getMonth(): Month (0-11)
- getDate(): Day of month
- getDay(): Day of week (0=Sun)
- getHours(): Hours
- getMinutes(): Minutes
- getSeconds(): Seconds
- getTime(): Timestamp
- setFullYear(year): Change year
6. JSON Methods
- JSON.stringify(obj): Object -> string
- JSON.parse(str): String -> object
7. Utility
- setTimeout(fn, ms): Delay execution
- setInterval(fn, ms): Repeat execution
- clearTimeout(id): Stop timeout
- clearInterval(id): Stop interval
- alert(msg): Show alert box
- prompt(msg): Input from user
- confirm(msg): Yes/No box