10 JavaScript methods I use daily as a junior web developer

Upekka Chakma
2 min readMay 5, 2021

Array.map(): This method returns a new array with the result of calling a function for every item in the array.

Array.reduce(): reduces all element of an array into a single element(result). It takes two arguments. 1st is callback method which runs each items against other in the array and 2nd is initial value.

Array.filter(): loops through all elements of an array and creates a new array with elements that fulfills the condition.

Example: const salary = [ 10, 21, 23, 29];

const goodSalary =(salary) => {

return salary >=20;

};

Const result = salary.filter(goodSalary); // returns [21, 23, 29]

Array.push(): pushes new elements to an array and returns new length.

Math.abs(): converts any numbers to it’s real world numbers/ positive numbers.

Example: Math.abs(-5); // 5;

passing an empty array, empty string or NULL will return 0. However, empty object, string or no value will return NaN.

Math.round(): returns value of a floating number closest to its integer values.

Example: Math.round(1.6); // 2;

Math.sqrt(-4.3); // -4;

Math.sqrt(): returns square root of a number. Returns NaN for negative integers.

Example: Math.sqrt(16); // 4;

Math.sqrt(-16); // NaN;

passing an empty array, empty string or NULL will return 0. However, empty object, string or no value will return NaN.

parseInt(): parses a string, returns integer. If the string begins with “0x”, then it will return a hexadecimal number. Octal numbers for strings that begin with “0”, otherwise it will return decimal format.

charAt(): returns a char value at a given index numbers.

Example: const a = “Yes”;

const b = a.charAt(2); // returns “s”

indexOf(): searches an array for a particular item and returns index number of that item in the array. Returns -1 if item not found.

Example: const x = [“m”, “n”, “y”];

const y = x.indexOf(“n”); //returns 1

Const z = x.indexOf(“o”); //returns -1

--

--