arrX = ['aaa','ccc','bbb','其他'];
const otherIndex = arrX.indexOf('其他'); // 找到"其他"的索引
// 如果找到了"其他"
if (otherIndex !== -1) {
// 移除"其他"
const tempItems = arrX.slice();
tempItems.splice(otherIndex, 1);
// 将"其他"添加到数组末尾
tempItems.push('其他');
// 更新原数组
arrX = tempItems;
}
dsType.xData = arrX
arrY= [{name:'aaa',value:1},{name:'bbb',value:1},{name:'ccc',value:1},{name:'其他',value:1}];
const moveItemToLast = (array, itemName) => {
// 使用filter将不包含特定项的其他项分离出来
const otherItems = array.filter(item => item.name !== itemName);
// 找到需要移动到最后的项
const itemToMove = array.find(item => item.name === itemName);
// 如果找到了该项,将其与其余项连接并返回新数组
if (itemToMove) {
return otherItems.concat(itemToMove);
}
// 如果没有找到,返回原数组
return array;
};
dsType.yData = moveItemToLast(arrY, '其他');
07-18
1909
05-31
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交