js正常语法
//存在唯一索引的对象数组,-1表示不存在
let i = checkedGoodsAttributes.findIndex(function(item){return item.goods_attribute_uuid == checkedAttr.goods_attribute_uuid})
if (i != -1){
checkedGoodsAttributes.splice(i,1)
}
// 数值类数组
let j = checkedCartUuids.indexOf(uuid);
if (j != -1){
checkedCartUuids.splice(j, 1)
}
ES6箭头语法
let i = checkedGoodsAttributes.findIndex(item=>item.goods_attribute_uuid == checkedAttr.goods_attribute_uuid)
if (i != -1){
checkedGoodsAttributes.splice(i,1)
}
let j = checkedCartUuids.indexOf(uuid);
if (j != -1){
checkedCartUuids.splice(j, 1)
}
JavaScript与ES6数组操作
这篇博客探讨了如何使用JavaScript的findIndex方法和splice方法来处理数组中的元素。示例展示了在存在唯一索引的对象数组和数值类数组中查找并删除特定元素的过程,对比了传统语法和ES6箭头函数的写法,强调了ES6语法的简洁性。
1万+

被折叠的 条评论
为什么被折叠?



