微信小程序——删除数组中指定元素

时间:2025-03-21 10:03:49

1、(index,howmany)

  • index:表示从指定的位置上(哪里)删除元素;
  • howmany:表示应该删除多少个元素,赋值为0就表示不删除元素;

2、() 当数组中的元素在测试条件时返回 true 时, findIndex() 返回符合条件的元素的索引位置;如果没有符合条件的元素返回 -1

示例:

.wxml文件

<view  wx:for="{{productList}}" wx:for-item="item" wx:key="index"  data- bindtap="doDel">
<view class="">{{}}</view>
<view class="">{{}}</view>
</view>

.js文件

page({
	data: {
	productList: []
},
	doDel: function (e) {
    const that = this
(( index => index === ), 1)
    ({
        productList: 
    })
    }
})