0
<script>

window.onload = start;

function start() {
word(["S"+"U"+"Z"],["D"+"A"+"R"])

}

function word(a,b) {

 var letters = a+b
for (var i = 0; i < letters.length; i++) {
}
document.getElementById("utskrift").innerHTML=letters
}
</script>

Okay so this code works completely fine. My letters come out as "SUZDAR", but i wanna be able to remove the "+" symbol in my argument "Word" and replace it with commas. so the argument becomes (["S","U","Z"],["D","A","R"]). The question is, how do i remove the commas and get the same output as i currently have without the "+" symbols. I dont know how to use the split function here.

3 Answers 3

1

Just use the join function:

var letters = a.join('') + b.join('');
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much, could you explain short what the join(' ') does?
Join will concatenation the items in the array, placing the argument of the function between each item. The result will be a string. For example, [1,2,3].join(‘xx’) will be ‘1xx2xx3’
1

Use Array#concat() to merge the 2 arrays and Array#join() to merge array items to string

function word(a,b){
 return a.concat(b).join('')
}

console.log(word(["S","U","Z"],["D","A","R"]))

Comments

0

use join() function to combine all your array elements into single string value.

join() function will add a default separator (comma) for each pair of adjacent elements of the array. The separator is converted to a string and the output will be like,

letters.join(); //returns S,U,Z,D,A,R

To remove the ',' value you need to mention empty string ('') as parameter to join function. If separator is an empty string, all elements are joined without any characters in between them.

letters.join(''); //returns SUZDAR

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.