参考: https://developer.mozilla. org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/join How come the | is not added when I call the join method var array ="12|23|435|566|46|6|666766|24"; var arraySplit = array.split("|"); var newArray = []; for (i=0; i<arraySplit.length; i++) { if (arraySplit[i] < 500) { newArray.push(arraySplit[i]); } } newArray.join("|"); alert(newArray); 解决方案 newArray.join does not modify the existing array. It returns a new string of all the array's current values, joined by the string you specify. Use the following to store the generated array in a new variable:var joinedArray = newArray.join("|");alert(joinedArray);DEMO: http://jsfiddle.net/EH8dB/References:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join 这篇关于JavaScript拆分,推送和加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 22:01