Split a String into an Array Using the split Method
Problem Explanation
Simply split the string to create a new array of words.
A simple regular expression can be used to achieve this result.
/\W/
Matches any non-word character. This includes spaces and punctuation, but not underscores. It’s equivalent to /[^A-Za-z0-9_]/
. For more information about Regular Expressions, see the official MDN Documentation.
Solutions
Solution 1 (Click to Show/Hide)
function splitify(str) {
// Add your code below this line
return str.split(/\W/);
// Add your code above this line
}
splitify("Hello World,I-am code");