js数组对象,数组集合。js集合数组找位置找下标。查找数组中某个对象的位置。数组根据下标删除 电脑版发表于:2023/11/21 9:42 [TOC] #### 手写 for 循环 ``` let arr = [{ name: 'jin', code: 1 }, { name: 'chang', code: 2 } ...] let obj = { name: 'jin', code: 1 } for(let i = 0, iLen = arr.length; i < iLen; i++) { if (arr[i].code === obj.code) { return i } } ``` #### 使用findIndex ``` let arr = [{ name: 'jin', code: 1 }, { name: 'chang', code: 2 } ...] let obj = { name: 'jin', code: 1 } arr.findIndex((el) => { return el.code === obj.code }) ``` ##### ts中的使用 ``` let index = _circlesItem?.taskLikes.findIndex((el:any) => el.likeDescId == res.data.taskLike.likeDescId && el.userId == res.data.taskLike.userId) ``` #### 数组根据下标删除 ``` _circlesItem?.taskLikes.splice(index, 1); ```