From f52b1bcf1be5960de1b34bf6d7d94187008c8c12 Mon Sep 17 00:00:00 2001 From: JoyelJohny Date: Sun, 8 Oct 2023 16:21:44 +0530 Subject: [PATCH 1/6] Added replaceAll() term in javascript/strings --- .../strings/terms/replaceAll/replaceAll.md | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 content/javascript/concepts/strings/terms/replaceAll/replaceAll.md diff --git a/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md b/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md new file mode 100644 index 00000000000..8cc07e5ecf7 --- /dev/null +++ b/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md @@ -0,0 +1,34 @@ +--- +Title: '.replaceAll()' +Description: 'Returns a new string by replacing all the matches of searchValue by replacementValue' +Subjects: + - 'Web Development' + - 'Computer Science' +Tags: + - 'Strings' + - 'Methods' +CatalogContent: + - 'introduction-to-javascript' + - 'paths/front-end-engineer-career-path' +--- + +Returns a new string by replacing all the matches of searchValue by replacementValue. + +## Syntax + +```js +string.replaceAll(searchValue, replacementValue); +``` + +The `searchValue` can be either a [string](https://www.codecademy.com/resources/docs/javascript/strings) or [RegExp](https://www.codecademy.com/resources/docs/javascript/regexp). + +## Example + +Replace all the word `'scream'` with `'laugh'`: + +```js +const sentence = `I scream, you scream, we all scream for ice cream.`; + +console.log(sentence.replaceAll('scream', 'laugh')); +// Output: I laugh, you laugh, we all laugh for ice cream. +``` From e5f0c90caf6c6b1ee2317e1ddf1e6839fcc5a105 Mon Sep 17 00:00:00 2001 From: Joyel Johny <81413791+JoyelJohny@users.noreply.github.com> Date: Mon, 9 Oct 2023 08:29:35 +0530 Subject: [PATCH 2/6] Update content/javascript/concepts/strings/terms/replaceAll/replaceAll.md Co-authored-by: SSwiniarski <86081858+SSwiniarski@users.noreply.github.com> --- .../javascript/concepts/strings/terms/replaceAll/replaceAll.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md b/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md index 8cc07e5ecf7..68c267debf1 100644 --- a/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md +++ b/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md @@ -1,6 +1,6 @@ --- Title: '.replaceAll()' -Description: 'Returns a new string by replacing all the matches of searchValue by replacementValue' +Description: 'Returns a new string by replacing all the matches of a given search value with a given replacement value.' Subjects: - 'Web Development' - 'Computer Science' From b6e2f50483706b58e152ff7e66929f2d61dfc4dd Mon Sep 17 00:00:00 2001 From: Joyel Johny <81413791+JoyelJohny@users.noreply.github.com> Date: Mon, 9 Oct 2023 08:30:51 +0530 Subject: [PATCH 3/6] Update content/javascript/concepts/strings/terms/replaceAll/replaceAll.md Updated example Co-authored-by: SSwiniarski <86081858+SSwiniarski@users.noreply.github.com> --- .../javascript/concepts/strings/terms/replaceAll/replaceAll.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md b/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md index 68c267debf1..37d5c858d0c 100644 --- a/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md +++ b/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md @@ -24,7 +24,7 @@ The `searchValue` can be either a [string](https://www.codecademy.com/resources/ ## Example -Replace all the word `'scream'` with `'laugh'`: +Replace all the occurrences of "scream" with "laugh": ```js const sentence = `I scream, you scream, we all scream for ice cream.`; From 1d78a8c872857a9c54964fe8e2a53648ddfe72b6 Mon Sep 17 00:00:00 2001 From: Joyel Johny <81413791+JoyelJohny@users.noreply.github.com> Date: Mon, 9 Oct 2023 08:31:50 +0530 Subject: [PATCH 4/6] Update content/javascript/concepts/strings/terms/replaceAll/replaceAll.md Updated description Co-authored-by: SSwiniarski <86081858+SSwiniarski@users.noreply.github.com> --- .../javascript/concepts/strings/terms/replaceAll/replaceAll.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md b/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md index 37d5c858d0c..54587e24980 100644 --- a/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md +++ b/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md @@ -12,7 +12,7 @@ CatalogContent: - 'paths/front-end-engineer-career-path' --- -Returns a new string by replacing all the matches of searchValue by replacementValue. +Returns a new string by replacing all the matches in a string of a given search value with a given replacement value. ## Syntax From 8f92bf1c35d5b5c39549e1761b2e6b08b21000e5 Mon Sep 17 00:00:00 2001 From: Joyel Johny <81413791+JoyelJohny@users.noreply.github.com> Date: Mon, 9 Oct 2023 08:41:07 +0530 Subject: [PATCH 5/6] Update replaceAll.md Updated Shell Output --- .../concepts/strings/terms/replaceAll/replaceAll.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md b/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md index 54587e24980..e41bcad15a5 100644 --- a/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md +++ b/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md @@ -30,5 +30,10 @@ Replace all the occurrences of "scream" with "laugh": const sentence = `I scream, you scream, we all scream for ice cream.`; console.log(sentence.replaceAll('scream', 'laugh')); -// Output: I laugh, you laugh, we all laugh for ice cream. +``` + +This example results in the following output: + +```shell +"I laugh, you laugh, we all laugh for ice cream." ``` From 3e37390d1b8db3c6dd449cb274250aae79b16764 Mon Sep 17 00:00:00 2001 From: Christine Yang <72277593+yangc95@users.noreply.github.com> Date: Mon, 9 Oct 2023 12:48:59 -0400 Subject: [PATCH 6/6] Update replaceAll.md --- .../concepts/strings/terms/replaceAll/replaceAll.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md b/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md index e41bcad15a5..da502c02fcf 100644 --- a/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md +++ b/content/javascript/concepts/strings/terms/replaceAll/replaceAll.md @@ -12,11 +12,11 @@ CatalogContent: - 'paths/front-end-engineer-career-path' --- -Returns a new string by replacing all the matches in a string of a given search value with a given replacement value. +The **`.replaceAll()`** method returns a new string by replacing all the matches in a string of a given search value with a given replacement value. ## Syntax -```js +```pseudo string.replaceAll(searchValue, replacementValue); ``` @@ -24,7 +24,7 @@ The `searchValue` can be either a [string](https://www.codecademy.com/resources/ ## Example -Replace all the occurrences of "scream" with "laugh": +Replace all the occurrences of `"scream"` with `"laugh"`: ```js const sentence = `I scream, you scream, we all scream for ice cream.`; @@ -35,5 +35,5 @@ console.log(sentence.replaceAll('scream', 'laugh')); This example results in the following output: ```shell -"I laugh, you laugh, we all laugh for ice cream." +I laugh, you laugh, we all laugh for ice cream. ```