String Split Join in JavaScript
Level 392 keystrokes
This splits a string by commas and then joins the array with dashes.
JavaScript code
// A comma-separated string1let str = "a,b,c,d";// split(",") cuts the string at each comma and returns an array2let arr = str.split(",");// Outputs ["a", "b", "c", "d"]3console.log(arr);// join("-") combines the elements into a string with "-" between them// Outputs "a-b-c-d"4console.log(arr.join("-"));Output
[ 'a', 'b', 'c', 'd' ] a-b-c-d
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
"× 6,× 4;× 4.× 4(× 4)× 4=× 2-× 1