A pot
Rose
A pot
Primrose
A pot
Rose
A pot
Rosemary
A pot
Rose
12345
let garden = [
	"Rose", "Primrose", 
	"Rose", "Rosemary", 
	"Rose"
];
123456
garden = garden
.map(plant =>
plant.replace(//i, "Blackberry")
)
);
Lesson 25 / 42

Lesson task •

Replace all the roses with blackberries

Replace part of string

String.prototype.replace

One of the most powerful features of regular expressions is that with regular expressions you can not only check if the substring is present in the string, but also replace a substring matching pattern with another string provided:

1
console.log("foo bar".replace(/foo/i, "baz")) // baz bar 

By default only first match will be replaced:

1
console.log("foo bar foo".replace(/foo/i, "baz")) // baz bar foo 

But later we'll see that there is a special flag that alters this behaviour