admin管理员组文章数量:1357302
while (j<secondSpecsArr.length) {
console.log(j);
if (regStr.test(secondSpecsArr[j])){
console.log('slice operation' + j + ' ' + secondSpecsArr[j]);
secondSpecsArr.slice(j,1);
} else { j++; }
}
I am deleting elements from Array, that include string 'strong'.
But its not deleting at least anything!
Like,
console.log('slice operation' + j + ' ' + secondSpecsArr[j]);` is working, but slice() isn'nt, and I get old array after this. Where's the problem?
while (j<secondSpecsArr.length) {
console.log(j);
if (regStr.test(secondSpecsArr[j])){
console.log('slice operation' + j + ' ' + secondSpecsArr[j]);
secondSpecsArr.slice(j,1);
} else { j++; }
}
I am deleting elements from Array, that include string 'strong'.
But its not deleting at least anything!
Like,
console.log('slice operation' + j + ' ' + secondSpecsArr[j]);` is working, but slice() isn'nt, and I get old array after this. Where's the problem?
- can you plese provide an example of console.log(secondSpecsArr); – Jurij Jazdanov Commented May 30, 2017 at 10:09
- 30 slice operation30 <strong>DVD+R</strong> : 16X<br> – andrey andrey Commented May 30, 2017 at 10:10
-
5
Array.prototype.slice()
: "The slice() method returns a shallow copy of a portion of an array into a new array object selected from begin to end (end not included). The original array will not be modified." – Andreas Commented May 30, 2017 at 10:10 -
slice
did not change your array. Usesplice
instead. – degr Commented May 30, 2017 at 10:11 - secondSpecsArr = secondSpecsArr.slice(j,1) maybe you are missing this – Jurij Jazdanov Commented May 30, 2017 at 10:11
1 Answer
Reset to default 11That is what slice
is for. It doesn't remove from the array, it extracts. splice
is removing from the array.
var a = [1,2,3];
a.slice(0,1) // [1]
//a = [1,2,3]
a.splice(0,1) // [1];
// a = [2,3]
splice
slice
本文标签: JavaScript slice() is not deleting elements from arrayStack Overflow
版权声明:本文标题:JavaScript slice() is not deleting elements from array - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744020202a2577058.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论