String replaceAll()
String replaceAll() is a JavaScript method (ES2021/ES2022) replacing all occurrences of a substring with another, returning a new string.
Syntax:
const newString = originalString.replaceAll(regexp | substr , newSubstr | function)
Example: Below is an example of the String replaceAll() Method.
Javascript
function gfg() { let string = "Geeks or Geeks" ; newString = string.replaceAll( "or" , "for" ); console.log(newString); } gfg(); |
Output
Geeks for Geeks
ECMAScript 2021 (JS 2021/2022)
JavaScript in 2021/2022 continues to evolve, with ES2021/ES2022 bringing enhanced features like private class fields, promise improvements, and record data structures, boosting developer productivity and code quality.