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
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
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
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
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
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
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
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' ]
Please comment your thoughts about it or just like it :)
Top comments (2)
Thank you very much! I am new to coding and this was very informative. :)
@tishluvtech You are welcome :)