Giardinetto

Javascript Cheatsheet

Functions

String methods

string1.concat(string2) - Join two strings together
string1.indexOf(char) - Find the index of a character in a string
string1.split(',') - Split a string up based on a particular character
.slice() - Allows you to slice characters in a string
string.replace('s','p') - Replace the first instance of a particular char
string.replaceAll('s','p') - Replace all instances of a particular char in a string
.toLowerCase()/.toUpperCase() - Mutates string to be lower or upper case
Number(string) - Mutates string into a number
string.toString() - Mutates other datatype into a string
string.replace(/\W/g, ''); - Replaces all non alpha-numerical characters

Array methods

array.filter() - words.filter(word => word.length > 6);
array.reverse() - Reverses an array
array.map() - array1.map(x => x * 2);
array.find() - array1.find(element => element > 10);
array.sort() - months.sort();
array.slice() - slice(start, end) (extracts)
array.splice() - splice(start, deleteCount, item1) (replaces)
array.join() - concatenates
array.reduce() - reduce((acc, curr) => acc + curr),0);
array.forEach() - .forEach(element => console.log(element));
array.includes(string) - Checks if a value is included in an array

Object methods

Object.entries()
Object.fromEntries()
Object.getOwnPropertyNames()
Object.keys()
Object.prototype.hasOwnProperty()
Object.values()

Mathematical operations

Math.sign(x) - Checks if negative
const mode = Number(Object.keys(obj).reduce((a, b) => obj[a] > obj[b] ? a : b))
const mean = array.reduce((acc,curr) => acc + curr,0) / array.length;

Misc knowledge