DEV Community

Cover image for Most Commonly Used JavaScript Methods in 2023
Kate Galushko
Kate Galushko

Posted on

Most Commonly Used JavaScript Methods in 2023

Here is my list of the most commonly used JavaScript methods. If I missed something please comment.

LENGTH
The Length method is use for get the numbers of characters in a string including white space.

const str = "Thisis my code";
console.log(str.length);

Output: 14
Enter fullscreen mode Exit fullscreen mode

You can use also this method to get the length of any array in Javascript.

SLICE
slice() method is use for extracts a part of a string from a string and returns the extracted part in new string.

const str1 = 'Thisismycode';
var output = str1.slice(6 , 12);

console.log(output);
// Output: code
Enter fullscreen mode Exit fullscreen mode

REPLACE
The replace() method is use for replace a specific value with another value in a string.

// replace method
const str2 = 'Thisismycode';
var output1 = str2.replace('my' , 'our');

console.log(output1);
// output: Thisisourcode
Enter fullscreen mode Exit fullscreen mode

UPPER AND LOWER CASE
toLowerCase() method is use to convert the all character of a string into lower case and toUpperCase() method is use to convert the all character of a string into upper case.

// upper and lower case method
const str3 = 'ThisismyCode';
var output2 = str3.toLowerCase();
var output3 = str3.toUpperCase();

console.log(output2);
console.log(output3);

// Output: 
thisismycode
THISISMYCODE
Enter fullscreen mode Exit fullscreen mode

CONCAT
The method concat() is use for join two or more string.

// concat method
const str4 = 'Thisismy';
var output4 = str4.concat('code');

console.log(output4);

// output: Thisismycode
Enter fullscreen mode Exit fullscreen mode

Here is another great example of how to concatenate two strings in javascript.

TRIM
The trim() method removes the white space from both side in a string.

// trim method
const str5 = '     i love my code      ';
var output5 = str5.trim();

console.log(output5);

// output: 
i love my code
Enter fullscreen mode Exit fullscreen mode

CHARAT
The charAt() method is use for get a character at a specific index from a string.

// charat method
const str6 = 'ILoveMyCode';
var output6 = str6.charAt(5);

console.log(output6);

//outout: M
Enter fullscreen mode Exit fullscreen mode

SPLIT
The split() method is use to converts a string into an array.

// split method
const str7 = 'I ,Love ,My ,Code';
var output7 = str7.split(',');

console.log(output7);

//output: 
[ 'I ', 'Love ', 'My ', 'Code' ]
Enter fullscreen mode Exit fullscreen mode

Please comment your thoughts about it or just like it :)

Top comments (2)

Collapse
 
tishluvstech profile image
LaTisha Douglas

Thank you very much! I am new to coding and this was very informative. :)

Collapse
 
aliegotha profile image
Kate Galushko

@tishluvtech You are welcome :)