Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

edited title
Link
DarkBee
  • 14.4k
  • 9
  • 86
  • 135

How do I replace all occurrences of a string in JavaScript?

added 15 characters in body
Source Link
mikemaccana
  • 126.3k
  • 113
  • 442
  • 545

Given a string:

sstring = "Test abc test test abc test test test abc test test abc";

This seems to only remove the first occurrence of abc in the string above:

sstring = sstring.replace('abc', '');

How do I replace all occurrences of it?

Given a string:

s = "Test abc test test abc test test test abc test test abc";

This seems to only remove the first occurrence of abc in the string above:

s = s.replace('abc', '');

How do I replace all occurrences of it?

Given a string:

string = "Test abc test test abc test test test abc test test abc";

This seems to only remove the first occurrence of abc in the string above:

string = string.replace('abc', '');

How do I replace all occurrences of it?

Shorten.
Source Link
Mateen Ulhaq
  • 27.9k
  • 22
  • 122
  • 155

How todo I replace all occurrences of a string in JavaScript?

I have thisGiven a string in my JavaScript code:

s = "Test abc test test abc test test test abc test test abc"abc";

DoingThis seems to only remove the first occurrence of abc in the string above:

strs = strs.replace('abc', '');

Seems to only remove the first occurrence of abc in the string above.

How cando I replace allall occurrences of it?

How to replace all occurrences of a string in JavaScript

I have this string in my JavaScript code:

"Test abc test test abc test test test abc test test abc"

Doing:

str = str.replace('abc', '');

Seems to only remove the first occurrence of abc in the string above.

How can I replace all occurrences of it?

How do I replace all occurrences of a string in JavaScript?

Given a string:

s = "Test abc test test abc test test test abc test test abc";

This seems to only remove the first occurrence of abc in the string above:

s = s.replace('abc', '');

How do I replace all occurrences of it?

A question mark deserves a question formed as such (QUASM) - the "How to ... ?" form is broken English (caused by illiteracy).
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 110
  • 134
Loading
edited body; edited title
Source Link
Penny Liu
  • 18k
  • 5
  • 89
  • 109
Loading
specifically indicating the language used in the question in addition to the tags
Source Link
Loading
edited title
Link
Termininja
  • 7k
  • 12
  • 51
  • 50
Loading
Fixed the question formation - missing auxiliary (or helping) verb - see e.g. <https://www.youtube.com/watch?v=t4yWEt0OSpg&t=1m49s> (see also <https://www.youtube.com/watch?v=kS5NfSzXfrI> (QUASM)).
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 110
  • 134
Loading
added 4 characters in body; edited tags; edited title
Source Link
Alexander Abakumov
  • 14.7k
  • 16
  • 99
  • 135
Loading
Active reading.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 110
  • 134
Loading
not related with node.js
Link
Yasen
  • 3.4k
  • 1
  • 29
  • 22
Loading
edited tags
Link
KARTHIKEYAN.A
  • 20.5k
  • 11
  • 139
  • 151
Loading
removed excessive node.js tag
Link
Yasen
  • 3.4k
  • 1
  • 29
  • 22
Loading
tag added
Link
KARTHIKEYAN.A
  • 20.5k
  • 11
  • 139
  • 151
Loading
deleted 11 characters in body; edited tags; edited title
Source Link
Termininja
  • 7k
  • 12
  • 51
  • 50
Loading
Question Protected by Pankaj Parkar
Question Unprotected by Pankaj Parkar
Question Protected by Community Bot
deleted 4 characters in body; edited title
Source Link
JJJ
  • 33.2k
  • 20
  • 95
  • 103
Loading
Post Merged (destination) from stackoverflow.com/questions/832257/javascript-multiple-replace
added 12 characters in body
Source Link
user21926
user21926
Loading
spelling
Source Link
Carl Manaster
  • 40.5k
  • 17
  • 109
  • 158
Loading
Source Link
Ali
  • 268.1k
  • 270
  • 595
  • 789
Loading
lang-js

AltStyle によって変換されたページ (->オリジナル) /