admin管理员组文章数量:1356889
How e 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);
How e 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);
Share
Improve this question
asked Oct 13, 2012 at 0:14
mporampora
1,4795 gold badges26 silver badges67 bronze badges
1
- Have a look at MDN's documentation: developer.mozilla/en-US/docs/JavaScript/Reference/… – Felix Kling Commented Oct 13, 2012 at 0:38
2 Answers
Reset to default 7newArray.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/EH8dB/
References:
- https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join
You are not modifying newArray since join() returns a new object.
本文标签: Javascript splitpush and joinStack Overflow
版权声明:本文标题:Javascript split, push and join - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744000583a2573785.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论