A Short List of Methods Every JavaScript Developer Must Know

A List of String, Number, Math and Array Methods

String Methods: includes(), replace(), slice(), split()

var str = “Hello world, from the medium blog.”;
var n = str.includes(“medium”);
console.log(n) // the output is 'true'
var n = str.includes(“Medium”);
console.log(n) // the output is 'false' due to case sensitivity
var str = "This method searches for a given string.";
var res = str.replace("method", "function");
console.log(res) // This function searches for a given string.
var str = "Hello world!";
var res = str.slice(3, 8);
console.log(res); // lo wo
var res = str.slice(3);
console.log(res); // lo world!
var res = str.slice(-4);
console.log(res); // rld!
var str = "How are you?";
var res = str.split("");
console.log(res); // ['H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u', '?']
var res = str.split();
console.log(res); // ['How are you?']
var res = str.split(" ");
console.log(res); // ['How', 'are', 'you?']

Number Methods: isNaN(), parseInt(), random()

console.log(Number.isNaN(NaN)) //true
console.log(Number.isNaN(0 / 0)) //true
console.log(Number.isNaN(123)) //false
console.log(Number.isNaN(true)) //false
Math.floor((Math.random() * 100) + 1);
console.log(parseInt("10.33")) // 10
console.log(parseInt("10", 8)) // 8
console.log(parseInt("He was 40")) // NaN

Array Methods: filter(), map(), reduce(), slice(), splice()

const nums = [2,4,1,8,6];
// get the even numbers
const newNums = nums.filter(num => num % 2 === 0);
console.log(newNums) // [2,4,8,6]
const nums = [2,4,1,8,6];
const newNums = nums.map(num => num * num);
console.log(newNums) // [4, 16, 1, 64, 36]
const nums = [2,4,1,8,6];
const total = nums.reduce((sum, num)=> {
return sum + num;
}, 0);
console.log(total) // 21
var chars = ["A", "B", "C", "D", "E"];
console.log(chars.slice(1, 3)); // ["B", "C"]
console.log(chars.slice(2)); // ["C", "D", "E"]
// At position 1, add the new items, and remove 3 item
var chars = ["A", "B", "C", "D", "E"];
console.log(chars.splice(1, 3, "F", "G")); // ["A", "F", "G", "E"]

I am a Front-End Developer. I love to work with JavaScript, ReactJS, NodeJS, React Native and other front-end and/or JavaScript based technologies.