当前位置:网站首页>JS实现上一个、下一个、置顶、置底操作
JS实现上一个、下一个、置顶、置底操作
2022-08-04 05:26:00 【qq_26695613】
废话不多说,直接上代码。
//index1和index2分别是两个数组的索引值,即是两个要交换元素位置的索引值,如1,5就是数组中下标为1和5的两个元素交换位置
export function swapArray(arr, index1, index2) {
arr[index1] = arr.splice(index2, 1, arr[index1])[0];
return arr;
}
//置顶
export function zd(arr,index){
if(index!=0){
arr.unshift(arr.splice(index,1)[0])
}else{
alert('已经处于最上');
}
}
//置底
export function zdd(arr,index){
if(index!=arr.length-1){
var temp=arr[index];//
arr.splice(index,1);
arr.push(temp);
// arr.unshift(arr.splice(index,1)[0])
// arr.reverse();
}else{
alert('已经处于最下');
}
}
//上移 将当前数组index索引与后面一个元素互换位置,向数组后面移动一位
export function zIndexUp(arr,index,length){
debugger
if(index+1 != length){
swapArray(arr, index, index+1);
}else{
alert('已经处于最下,无法下移');
}
}
//下移 将当前数组index索引与前面一个元素互换位置,向数组前面移动一位
export function zIndexDown(arr,index,length){
if(index!= 0){
swapArray(arr, index, index-1);
}else{
alert('已经处于最上,无法上移');
}
}
边栏推荐
- Summary of MySQL database interview questions (2022 latest version)
- 4.3 基于注解的声明式事务和基于XML的声明式事务
- MySQL日期函数
- Unity DOTS学习教程汇总
- 【Matlab仿真】:一带电量为q的电荷以速度v运动,求运动电荷产生磁感应强度
- Unity表格配置编辑工具
- SLSA 框架与软件供应链安全防护
- 如何将 DevSecOps 引入企业?
- Embedded system driver primary [4] - under the basis of character device driver _ concurrency control
- TensorRTx-YOLOv5工程解读(二)
猜你喜欢
随机推荐
【问题解决】同一机器上Flask部署TensorRT报错记录
利用Jenkins实现Unity自动化构建
Delphi-C端有趣的菜单操作界面设计
Linux环境下redis的下载、安装和启动(建议收藏)
(Kettle) pdi-ce-8.2 连接MySQL8.x数据库时驱动问题之终极探讨及解决方法分析
基于C语言的学生信息管理系统_(更新版)_(附源码和安装包)_课程设计_**往事随風**的博客
4.1 JdbcTemplate for declarative transactions
Programming hodgepodge (3)
PHP实现异步执行程序
将自定义类型作为关联容器的key
记录获取参赛选手信息过程
Can‘t connect to MySQL server on ‘localhost3306‘ (10061) 简洁明了的解决方法
Plus版SBOM:流水线物料清单PBOM
12. Paging plugin
实际开发中左菜单自定义图标点击切换
The cost of automated testing is high and the effect is poor, so what is the significance of automated testing?
Web Basics and Exercises for C1 Certification - My Study Notes
箭头函数的使用
phpexcel导出数据为xml
【JS】js给对象动态添加、设置、删除属性名和属性值









