改变一个数组内元素的位置,不通过splice方法。

2022-11-13,,,,

这个数据

现在已经完成了,将本来在第一位的18代金券改到第31位,下面说一下怎么实现的。

//currHotRightsTypeSorted这个是数据源头,legalRightsType这个是数据的分类,因为18元代金券只在两个分类中
//1对数据进行遍历,找打需要分类中某个元素并赋值给一个新的元素,以后用,并删除他,通过他的i值。
//2如果数据分类数据中的长度小于31位时,放到最后一位。
currHotRightsTypeSorted.forEach((num: any) => {
let tmp = '';
if (num.legalRightsType == '1015' || num.legalRightsType == '----') {
for (let i = 0; i < num.list.length; i++) {
if (num.list[i].legalRightsNbr === 'QY1622613823700') {
tmp = num.list.splice(i, 1);
}
}
if (num.list.length >= 31) {
num.list.splice(30, 0, tmp[0]);
} else {
num.list.push(tmp[0]);
}
}
});

改变一个数组内元素的位置不通过splice方法。的相关教程结束。

《改变一个数组内元素的位置,不通过splice方法。.doc》

下载本文的Word格式文档,以方便收藏与打印。