当前位置:网站首页>Js array operating mobile for encapsulation
Js array operating mobile for encapsulation
2022-07-30 10:14:00 【Your beauty fascinates me】
//1.Swap two array elements
export function swapArr(arr, index1, index2) {
arr[index1] = arr.splice(index2, 1, arr[index1])[0];
return arr;
}
//2.Brings an element to the top
export function toFirst(fieldData,index) {
if(index!=0){
// fieldData[index] = fieldData.splice(0, 1, fieldData[index])[0]; This method swaps places with another element,
fieldData.unshift(fieldData.splice(index , 1)[0]);
}
}
//3.Moves the specified element up one space
export function upGo(fieldData,index){
if(index!=0){
fieldData[index] = fieldData.splice(index-1, 1, fieldData[index])[0];
}else{
fieldData.push(fieldData.shift());
}
}
//4.Moves the specified element down one space
export function downGo(fieldData,index) {
if(index!=fieldData.length-1){
fieldData[index] = fieldData.splice(index+1, 1, fieldData[index])[0];
}else{
fieldData.unshift( fieldData.splice(index,1)[0]);
}
}
//5.Swap two elements in an array
export function swapArr(arr, index1, index2) {
arr[index1] = arr.splice(index2, 1, arr[index1])[0];
return arr;
}
//6.Move an element anywhere in the array to the end
export function toEnd(arr,index) {
arr.push(arr[index]);
arr.splice(index,1);
return arr;
}
//7.Array of deduplicated values,Any number of arrays can be filled,Either a single array can be deduplicated,It is also possible to merge multiple arrays to remove duplicates
//数组合并去重
export function combine(){
let arr = [].concat.apply([], arguments); //没有去重复的新数组
return Array.from(new Set(arr));
}
//8.删除指定元素,The first parameter is the array whose elements are to be removed,The second parameter is the element value to delete,The third value is whether strict mode is enabled(Variable types are strictly compared) 例如removeArr([1,2,3,4,5],2,false) 返回[1,3,4,5] 例如removeArr([1,2,3,4,5],2,true) 返回[1,2,3,4,5]
export function removeArr (arr,val,strict) {
let index;
if(strict===true){
index = arr.findIndex(x=>x===value);
}else{
index = arr.findIndex(x=>x==value);
}
if (index > -1) {
arr.splice(index, 1);
}
}
export function swapArr(arr, index1, index2) {
arr[index1] = arr.splice(index2, 1, arr[index1])[0];
return arr;
}
边栏推荐
- Always remember: one day you will emerge from the chrysalis
- Re20:读论文 What About the Precedent: An Information-Theoretic Analysis of Common Law
- Soft test system architects introductory tutorial | system operation and software maintenance
- 再有人问你分布式事务,把这篇扔给他
- 你真的懂Redis的5种基本数据结构吗?
- Beijing suddenly announced big news in the Metaverse
- mysql安装教程【安装版】
- 【深度学习】(问题记录)<对一个变量求梯度得到什么>-线性回归-小批量随机梯度下降
- Meikle Studio-Look at the actual combat notes of Hongmeng device development six-wireless networking development
- ThreadLocal内存泄漏是伪命题?
猜你喜欢

EViews 12.0 software installation package download and installation tutorial

PyQt5-用像素点绘制正弦曲线

leetcode 剑指 Offer 48. 最长不含重复字符的子字符串

Unified exception handling causes ResponseBodyAdvice to fail

JCL 学习

Redis Desktop Manager 2022.4.2 发布

连接mysql报错WARN: Establishing SSL connection without server‘s identity verification is not recommended

死锁的理解

Re19:读论文 Paragraph-level Rationale Extraction through Regularization: A case study on European Court

大数据产品:标签体系0-1搭建实践
随机推荐
leetcode 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
快解析结合象过河erp
Re20:读论文的先例:普通法的信息理论分析
EViews 12.0软件安装包下载及安装教程
通过构建一个顺序表——教你计算时间复杂度和空间复杂度(含递归)
软考 系统架构设计师 简明教程 | 系统运行与软件维护
JCL 学习
CVTE school recruitment written test questions + summary of knowledge points
【深度学习】(问题记录)<对一个变量求梯度得到什么>-线性回归-小批量随机梯度下降
In 2022, the top will be accepted cca shut the list
Flink_CDC搭建及简单使用
Test automation selenium (a)
分页 paging
Domino Server SSL Certificate Installation Guide
Re20:读论文 What About the Precedent: An Information-Theoretic Analysis of Common Law
论文阅读:SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers
Flask之路由(app.route)详解
JVM内存布局、类加载机制及垃圾回收机制详解
C语言顺序表基本操作
The creation of a large root heap (video explanation)