从数组中删除最后一项 [英] Remove last item from array
本文介绍了从数组中删除最后一项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下数组.
var arr = [1,0,2];
我想删除最后一个元素,即 2.
I would like to remove the last element i.e. 2.
我使用了 arr.slice(-1);
但它没有删除值.
I used arr.slice(-1);
but it doesn't remove the value.
推荐答案
使用 拼接(startPosition, deleteCount)
array.splice(-1)
var array = ['abc','def','ghi','123'];
var removed = array.splice(-1); //last item
console.log( 'array:', array );
console.log( 'removed:', removed );
这篇关于从数组中删除最后一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文