Help with Arrays (link inside)


The result of the quiz is the phrase “Programming,is,not,about,what,you,know,it,is,about,what,you,can,figure,out.,-2015,Chris,Pine,Learn,to,Program”

Is there any whay I could remove some of those commas, without changing permantly the array?

I would like to visualise this: Programming is not about what you know, it is about what you can figure out. -2015, Chris Pine, Learn to Program

Thank you.

Hello @jhonathanc. I am assuming this:

Is one array. If it is then:
You could use the .join() function, which takes an array Array.join(), and separates each element by the parameter provided, and returns a string:

let arr = ["1", "1", "1"];
arr = arr.join(" ");
console.log(arr);//prints "1 1 1"

You can read more about it here.

However, if this:

is just one string, then you can use the .replace() method. This by taking a string String.replace(), and replaces the first parameter with the second parameter. The first parameter must be a regular expression (but don’t worry, if you’re just doing simple text, you just enclose the character(s) that you want to replace in / /g:

let string1 = "a,b,c";
string1.replace(/,/g, " ");
console.log(string1); //prints "a b c"

You can read more about this method here.
I hope this helps!


very nice, thank you so much!

1 Like