Using the Todo List as a starting point, add support for adding multiple items at once. If you type into the text box "homework, exercise, shopping" you should end up with 3 items on your list.
The key here is to leverage String's split function.
Given a string, you can call split()
, passing in the delimiter
as an argument. In this case your delimiter is going to be ", "
since that's what people will be typing in. split()
will return
an array and then you can loop through that array with a for
loop.
var items = "homework, exercise, shopping".split(", ")
// => ["homework", "exercise", "shopping"]
for (var i = 0; i < items.length; i++) {
// do something with items[i]
}