Example 1: Replace All Instances Of a Character Using Regex
Output
LeArning JAvAScript ProgrAm
In the above example, the RegEx is used with the replace() method to replace all the instances of a character in a string.
/g represents that the operation is carried out for all in instances of the string.
Example 2: Replace All Instances Of Character Using Built-in Methods
Output
LeArning JAvAScript ProgrAm
In the above example, the built-in methods are used to replace all the occurrences of a character in a string.
The split('a') method splits the string into an array.
["Le", "rning J", "v", "Script Progr", "m"]
The join('A') method joins all the array elements into a string by adding A between each array element.
LeArning JAvAScript ProgrAm