首页 > 其他 > 详细

TypeScript Array Remove

时间:2019-04-05 18:32:51      阅读:245      评论:0      收藏:0      [点我收藏+]

定义一个数组

tags:any[];

方法1:filter
删除并不留空位

this.tags = this.tags.filter(tag => tag !== removedTag);

方法2:splice
删除并不留空位

const index = this.tags.indexOf(removedTag, 0);
if (index > -1) {
    this.tags.splice(index, 1);
}

方法3:remove
删除并留空位,会有empty占位

const index = this.tags.indexOf(removedTag, 0);
if (index > -1) {
    delete this.tags[index];
}

示例代码

示例代码

参考资料

How do I remove an array item in TypeScript?

TypeScript Array Remove

原文:https://www.cnblogs.com/Lulus/p/10659270.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!