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.
Example: This example shows the implementation of the above-explained approach.
// Define a string variable
let stone = "Soul";
// Use the padEnd() method to add padding characters
//" Power" to the end of the string 'stone'
stone = stone.padEnd(10, " Power");
// Output the resulting string after padding
console.log(stone);
Output
Soul Power
Explanation:
The code initializes a string variable stone with the value “Soul”. It then uses the padEnd() method to pad the string with spaces or a specified string (” Power”) until the resulting string reaches a length of 10 characters. Finally, it prints the modified string to the console, resulting in “Soul Power”.
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.