- searchVal: It is required parameter. It specifies the value, or regular expression, that is going to replace by the new value.
- newvalue: It is required parameter. It specifies the value to replace the search value with.
- separator: It is optional parameter. It specifies the character, or the regular expression, to use for splitting the string. If not used, the whole string will be returned (an array with only one item).
- limit: It is optional parameter. It holds the integer that specifies the number of splits, items beyond the split limit will be excluded from the array.
Example 1: This example replaces all spaces(‘ ‘) with underscores(“_”) by using replace() method.
Example 2: This example replaces all spaces(‘ ‘) with underscores(“_”) by using split() method. It first splits the string with spaces(” “) and then join it with underscore(“_”).
Please Login to comment...