JS String Methods : Boost Your JavaScript Skills with Essential String Methods: Complete Guide
Useful String methods in JavaScript. ( toLowerCase(), toUpperCase(), concat(), indexOf(), slice(), split(), replace(), substring() etc.)

Search for a command to run...
Useful String methods in JavaScript. ( toLowerCase(), toUpperCase(), concat(), indexOf(), slice(), split(), replace(), substring() etc.)

No comments yet. Be the first to comment.
Large language models can answer questions, write content, summarize information, and help with many other tasks. However, they have one important limitation: they do not automatically know everything

Uploading images directly from an Expo app to Amazon S3 can make your uploads faster and reduce work on your backend server. However, you should never put AWS access keys inside your Expo app. Anyone

Today, you do not need to pay for an AI API just to test AI models. You can run many open-source or open-weight AI models directly on your own laptop or PC. This means the model runs on your machine,

Deploying for Indian user data safety

Why I spent 3 years manually excluding IDE files from every single repo (and how one config line fixed everything)

In this Blog we are going to see what useful operations we can do on strings with built-in methods, such as finding the length of a text string, joining and splitting strings, substituting one character in a string for another, and more.
In JavaScript, string methods(🤔) are functions that operate on strings and allow you to perform various operations and manipulations on textual data or characters. These methods are available on string objects and are used to transform, extract, search, and modify strings. Here are some commonly used string methods in JavaScript.
(🤔): Method is a shorter syntax for defining a function property in an object initializer. It can also be used in classes.
Here are some commonly used string methods in JavaScript:
length: Returns the number of characters in a string.
const message = "Hello, World!";
console.log(message.length);
Output: 13
charAt() : Returns the character at specified position.
gameName = GTA5;
console.log(gameName.charAt(2));
Output = A
Note: JavaScript indexing starts from 0.
indexOf(): Returns the character of that single which is at that index. console.log(gameName.indexOf('A')); Output = 2
substring(): Returns a substring from a specified string.
const newString = gameName.substring(0,2)
console.log(newString);
Output = GTA
slice() : Return the substring but in slice reverse indexing (negative index number) is allowed.
anotherString = gameName.slice(-3,2);
console.log(anotherString);
Output= T
*mostly used
trim() : Trims the spaces from both ends of string.
const newStringOne = " aman ";
console.log(newStringOne);
console.log(newStringOne.trim());
Output: ‎ __aman__ // (with ends spacing)
aman // (without space at both ends)
replace() : Replaces a specified value in string to other specified value.
const url = "https://youtu.be/fozwNn%20Funlo"console.log(url.replace('%20','-'));
Output: https://youtu.be/fozwNn-Funlo
Includes() : Returns true if the string includes the specified value otherwise false. console.log(url.includes('foz'));
Output: true
concat(): This method is used to concatenate one or more strings together and returns a new string.
const str1 = 'Hello';
const str2 = 'World';
const result = str1.concat(' ', str2);
Output: 'Hello World'
toUpperCase(): This method converts all characters in a string to uppercase.
const str = 'hello';
const result = str.toUpperCase();
Output: 'HELLO'
toLowerCase(): This method converts all characters in a string to lowercase.
const str = 'HELLO';
const result = str.toLowerCase();
Output: 'hello'
Thanks for reading! If you enjoyed this article, consider following to my Hashnode blog account for more updates and insightful content. Feel free to leave a comment below sharing your thoughts, questions, or feedback. Let's stay connected!
Follow me on X | Connect on LinkedIn | Visit my GitHub
Copyright © 2024 Aman Raj. All rights reserved.