Reputation: 679
I want to clear all the whitespaces in the string arrayIsNowJoined
, and everywhere I look up target the solution I have...but it just doesn't work. I got the following code:
const array1 = ["1, 3, 4, 7, 16", "1, 2, 4, 16"];
let arrayIsNowJoined = array1.join();
arrayIsNowJoined.replace(/\s/g, "");
console.log(arrayIsNowJoined);
What I'm doing wrong?
Upvotes: 2
Views: 35
Reputation: 386736
You need an assignment of the result, because strings are immutable.
const array1 = ["1, 3, 4, 7, 16", "1, 2, 4, 16"];
let arrayIsNowJoined = array1.join();
arrayIsNowJoined = arrayIsNowJoined.replace(/\s/g, "");
console.log(arrayIsNowJoined);
Upvotes: 2
Reputation: 2627
You must assign variable after replace
arrayIsNowJoined = arrayIsNowJoined.replace(/\s/g, "");
Upvotes: 3