Important Javascript Build-In Methods (Cheatsheet)
Important Javascript Build-In Methods (Cheatsheet)
BUILD-IN METHODS
IMPORTANT CHEATSHEET
+91-7260058093
www.algotutor.io
1. Array Methods
forEach(): array.forEach(element => console.log(element));
map(): const squares = array.map(x => x * x);
filter(): const evens = array.filter(x => x % 2 === 0);
reduce(): const sum = array.reduce((acc, curr) => acc +
curr, 0);
find(): const found = array.find(x => x > 10);
indexOf(): const index = array.indexOf(item);
push(): array.push(item);
pop(): const lastItem = array.pop();
shift(): const firstItem = array.shift();
unshift(): array.unshift(item);
splice(): array.splice(startIndex, deleteCount, item);
slice(): const sliced = array.slice(startIndex, endIndex);
concat(): const mergedArray = array1.concat(array2);
join(): const str = array.join(', ');
includes(): const hasItem = array.includes(item);
some(): const hasNegative = array.some(x => x < 0);
every(): const allPositive = array.every(x => x > 0);
sort(): array.sort((a, b) => a - b);
reverse(): array.reverse();
2. String Methods
charAt(): const char = str.charAt(index);
concat(): const combinedStr = str1.concat(str2);
includes(): const hasSubstring = str.includes(substring);
indexOf(): const index = str.indexOf(substring);
lastIndexOf(): const lastIndex = str.lastIndexOf(substring);
match(): const matches = str.match(regex);
repeat(): const repeatedStr = str.repeat(times);
replace(): const replacedStr = str.replace(regex,
newSubstr);
search(): const index = str.search(regex);
slice(): const slicedStr = str.slice(startIndex, endIndex);
split(): const tokens = str.split(delimiter);
substring(): const substring = str.substring(startIndex,
endIndex);
toLowerCase(): const lowerStr = str.toLowerCase();
toUpperCase(): const upperStr = str.toUpperCase();
trim(): const trimmedStr = str.trim();
3. Object Methods
Object.keys(): const keys = Object.keys(obj);
Object.values(): const values = Object.values(obj);
Object.entries(): const entries = Object.entries(obj);
Object.assign(): const newObj = Object.assign({}, obj1,
obj2); Object.freeze(): const frozenObj =
Object.freeze(obj);
Object.isFrozen(): const isFrozen =
Object.isFrozen(obj);
Object.seal(): const sealedObj = Object.seal(obj);
Object.isSealed(): const isSealed =
Object.isSealed(obj);
Object.create(): const newObj =
Object.create(prototypeObj);
Object.hasOwnProperty(): const hasProp =
obj.hasOwnProperty(prop);
4. Number Methods
5. Math Functions
7. Date Methods