1

I have the following array, declared as "var strArry":

 <h4>  ``</h4>,<h4><font color="DarkSalmon">"We</font></h4>,<h4> wo </h4>,<h4><font color="ForestGreen">"'t comment on the</font></h4>,<h4>m . '' </h4>

It gives the following output of 5 strings, separated by commas:

``,"We, wo ,"'t comment on the,m . ''

I then call the array to form a continuous string without the commas by using the following command:

var htmlElementsforSrcLanguageSentence = htmlElementsforSrcLanguageSentence +strArry.join("");

The output it gives below is not what I need:

 ``
"We
wo
"'t comment on the
m . '' 

It is the removing the commas as expected but also placing each element in a new line. This doesn't work as I need to display it as one sentence. What am I missing?

1 Answer 1

1

Why don't you just use .toString() and then from there do a .replace() for the commas to be replaced with spaces?

var newArray     = new Array("item1", "item2", "item3", "item4");
var newString    = newArray.toString();
var editedString = newString.replace(/,/g, " ");
console.log(editedString);

Edit 1:

If you run that in a javascript console it does what you want, i'll go put a jsfiddle together for you.

Edit 2:

Here is the JS Fiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.