【发布时间】:2020-02-04 15:53:21
【问题描述】:
const myOldArr = [2, 3, 6];
const newArr = myOldArr.pop().shift();
为什么这样做会给我一个 TypeError?有没有办法在没有循环的情况下做到这一点?我希望将新数组存储在变量中,以便将未删除的剩余数字存储在某种数组中。
【问题讨论】:
-
popreturns the element that you popped。它不是一个数组,你可以在上面使用shift。 -
不要破坏您的帖子。通过在此站点上发布,您已不可撤销地授予 Stack Exchange 网络以CC BY-SA 4.0 license 分发该内容的权利,只要它认为合适即可。有关删除的替代方法,请参阅:I've thought better of my question; can I delete it?
标签: javascript