更好的一行代码解决方案:var answerInt = []; var answerString = "1 2 3 4"; answerString.split(' ').forEach(function (item) { answerInt.push(parseInt(item)) });