Warning: Undefined array key "night" in /www/wwwroot/dhaomu.com/wp-content/themes/b2/header.php on line 18

js移除元素属性-jquery删除所有子元素

Array.prototype.indexOf()

应用数据库索引搜索要删掉的二维数组原素的数据库索引,随后应用拼凑删除索引。

const array = [2, 5, 9];console.log(array);const index = array.indexOf(5);if (index > -1) { array.splice(index, 1);}// array = [2, 9]console.log(array);

拼凑的第二个主要参数是要清除的要素总数。一定要注意,拼凑会改动当政二维数组,并回到包括已清除原素的新二维数组。

为了更好地详细考虑,这里有一些涵数。第一个涵数只删掉一个配对项(即从[2,5,9,1,5,8,5]中删掉第一个配对项5),而第二个涵数删掉全部配对项。

function removeItemOnce(arr, value) { var index = arr.indexOf(value); if (index > -1) { arr.splice(index, 1); } return arr;}function removeItemAll(arr, value) { var i = 0; while (i < arr.length) { if (arr[i] === value) { arr.splice(i, 1); } else { i; } } return arr;}// Usageconsole.log(removeItemOnce([2,5,9,1,5,8,5], 5))console.log(removeItemAll([2,5,9,1,5,8,5], 5))

在TypeScript中,这种涵数能够加上种类主要参数。

function removeItem(arr: Array, value: T): Array { const index = arr.indexOf(value); if (index > -1) { arr.splice(index, 1); } return arr;}

Array.prototype.filter()

var value = 3var arr = [1, 2, 3, 4, 5, 3]arr = arr.filter(function(item) { return item !== value})console.log(arr)// [ 1, 2, 4, 5 ]

温馨提示:
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:duhaomu@163.com,我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读网站声明

给TA赞赏
共{{data.count}}人
人已赞赏
未整理

雨婷《服装直播带货运营落地实操课》新号0粉快速带货日销10W+

2021-7-31 0:00:00

未整理

XnSay机器人授权系统源码

2021-8-2 0:00:00

0 条回复 A文章作者 M管理员

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914
----《》
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索