You can use split(" ")
to split the string along white spaces.
To be more thorough, you should trim the leading and trailing spaces, and split along multiple space characters:
> var numbers_in_string = " 12 23 345 3454 21 ";
> var numbers_in_array = numbers_in_string.trim().split(/\s+/);
> console.log(numbers_in_arrays)
["12", "23", "345", "3454", "21"]
EDIT
As @Sangdol has mentioned, trim() may not work in IE9, so you can use include one of these solutions to add trim() functionality to IE9. Or just replace trim()
with replace(/^\s+|\s+$/g, '')
. Either solutions will work as a work-around for cross-browser compatibility.
.replace(/^\s+|\s+$/g, '').split(/\s+/)