JavaScript padStart() Method

JavaScript padStart() method pad a string with another string until it reaches the given length. The padding is applied from the left end of the string.

Example: This example shows the implementation of the above-explained approach.

JavaScript
// Define a string variable 
let stone = "Soul";

// Use the padStart() method to add padding characters "Mind "
//to the beginning of the string 'stone' 
stone = stone.padStart(9, "Mind ");

// Output the resulting string after padding
console.log(stone);

Output
Mind Soul

Explanation:

The code initializes a string variable stone with the value “Soul”. It then uses the padStart() method to pad the string with spaces or a specified string (“Mind “) until the resulting string reaches a length of 9 characters. Finally, it prints the modified string to the console, resulting in “Mind Soul”.

JavaScript String Methods

JavaScript strings are the sequence of characters. They are treated as Primitive data types. In JavaScript, strings are automatically converted to string objects when using string methods on them. This process is called auto-boxing.

JavaScript provides a bunch of string methods for representing and manipulating strings. From retrieving specific characters with charAt(), converting strings to uppercase with toUpperCase(), to combining strings with concat(), these methods simplify a wide range of tasks for developers. In this article, we will explore some essential JavaScript string methods that every developer should be familiar with.

Similar Reads

Basic JavaScript String Methods

JavaScript provides several built-in methods and properties for working with strings. Below is the list of JavaScript string functions that you need to know, for mastering JavaScript strings....

JavaScript slice() Method

JavaScript slice method extracts a part of the string based on the given stating-index and ending-index and returns a new string....

JavaScript substring() Method

JavaScript substring() method returns the part of the given string from the start index to the end index. Indexing starts from zero (0)....

JavaScript substr() Method

JavaScript substr() method This method returns the specified number of characters from the specified index from the given string. It extracts a part of the original string....

JavaScript replace()

JavaScript replace() method replaces a part of the given string with another string or a regular expression. The original string will remain unchanged....

JavaScript replaceAll()

JavaScript replaceAll() method returns a new string after replacing all the matches of a string with a specified string or a regular expression. The original string is left unchanged after this operation....

JavaScript toUpperCase()

JavaScript toUpperCase() method converts all the characters present in the String to upper case and returns a new String with all characters in upper case. This method accepts single parameter stringVariable string that you want to convert in upper case....

JavaScript toLowerCase()

JavaScript toLowerCase() method converts all the characters present in the so lowercase and returns a new string with all the characters in lowercase....

JavaScript concat() Method

JavaScript concat() method method combines the text of two strings and returns a new combined or joined string. To concatenate two strings, we use the concat() method on one object of string and send another object of string as a parameter. This method accepts one argument. The variable contains text in double quotes or single quotes....

JavaScript trim() Method

JavaScript trim() method is used to remove either white spaces from the given string. This method returns a new string with removed white spaces. This method is called on a String object. This method doesn’t accept any parameter....

JavaScript trimStart() Method

JavaScript trimStart() method removes whitespace from the beginning of a string. The value of the string is not modified in any manner, including any whitespace present after the string....

JavaScript trimEnd() Method

JavaScript trimEnd() method removes white space from the end of a string. The value of the string is not modified in any manner, including any white-space present before the string....

JavaScript padStart() Method

JavaScript padStart() method pad a string with another string until it reaches the given length. The padding is applied from the left end of the string....

JavaScript padEnd() Method

JavaScript padEnd() method pad a string with another string until it reaches the given length. The padding is applied from the right end of the string....

JavaScript charAt() Method

JavaScript charAt() method returns the character at the specified index. String in JavaScript has zero-based indexing....

JavaScript charCodeAt() Method

JavaScript charCodeAt() method returns a number that represents the Unicode value of the character at the specified index. This method accepts one argument....

JavaScript split() Method

JavaScript split() method splits the string into an array of sub-strings. This method returns an array. This method accepts a single parameter character on which you want to split the string....

More JS String Methods

Below is the JavaScript string functions list:...

Conclusion

JavaScript String is a collection of characters. They are one of the primitive data types. This tutorial covers these JavaScript string method that lets you manipulate strings....

Frequently Asked Questions – JavaScript String Methods

What are two string methods in JavaScript?...