当前位置:网站首页>[add, delete, modify, and check the array base]
[add, delete, modify, and check the array base]
2022-07-25 06:34:00 【If I become a demon, Buddha, I'm a program maniac】
Array addition and deletion
<body>
<script type="text/javascript">
// Operation array Add data Delete Copy lookup
var array = [1,2,3];
// array[array.length]=4;
// Add at the end of the array Additional
var res = array.push(5);
console.log(res);// The length of the array returned after appending
// Add... To the head of the array
res = array.unshift(0);
console.log(res);// Returns the length of the array
console.log(array);
// Delete the first data of the array
res = array.shift();
console.log(res);// Return the first deleted value
console.log(array);
// Delete the last bit of the array
res = array.pop();
console.log(res);// Return the last deleted value
console.log(array);
// Delete the element with the specified number of digits 1 2 3
console.log('--------splice-------------');
// splice(1,2,10) from 1 No. 1 position starts Delete 2 Lattice element And will 10 from 1 Add... At position No
res = array.splice(1,2,10);// The result is Deleted elements
console.log(res);
console.log(array);
// 1. Just write one parameter It will be deleted from the specified starting position to the end of the array Returns the deleted element as an array
// 2. Write two parameters From the specified location Delete the specified number of elements And return... As an array
// 3. Write three parameters Start at the specified location Delete the specified element , And add the new element from the specified starting position Return deleted elements
// var arr = [1,2,3,4,5,6];
// res = arr.splice(1);
// console.log(res);
// console.log(arr);
// Find elements in an array indexOf Find the position where the array first appears If there is a return subscript
// If there is no return -1
var array = [1,2,3];
res = array.indexOf(5);
console.log(res);// -1
res = array.indexOf(2);
console.log(res);//1
var array = [1,2,3,4];
console.log('--------slice-------------');
// Array truncation Does not affect the original array
res = array.slice(2,3);//2 Is the starting position of interception 3 It's the end position however 3 Position No. does not include re inside
console.log(res);
console.log(array);
res = array.slice(1);// from 1 Start intercepting at position No. to the end of the array
console.log(res);
console.log(array);
console.log('-------- Copy of array -------------');
// Copy of array
res = array.slice();
console.log(res);
console.log(array);
console.log('--------concat-------------');
// Array connection
var arr2=[5,6,7,8];
res = array.concat(arr2);
console.log(res);
res = array.concat();// Realize the copy of the array
console.log(res);
</script>
</body>边栏推荐
- [jailhouse article] base architectures for virtual physical computing (2018)
- Data too long for column 'data' at row 1 and the garbled code caused by setting to longblob are solved. node-mysql
- [datawhale202207] reinforcement learning: strategy gradient and near end strategy optimization
- In depth analysis: is the hottest business model in 2022 linked by 2+1 a legal model?
- Shell script realizes the scheduled backup of MySQL database on two computers
- Clear wechat applet and wechat H5 cache
- 函数模板学习记录
- GF Securities online account opening? Is it safe?
- When the graduation season comes, are you ready? What are we going to do
- 都说ScreenToGif是GIF录制神器,却不知其强大之处远不在此
猜你喜欢

Bubble sort code implementation
![[datawhale202207] reinforcement learning: the foundation of reinforcement learning](/img/1e/6ba657da14508854207aac51992ad8.png)
[datawhale202207] reinforcement learning: the foundation of reinforcement learning

Recycleview realizes horizontal sliding of overlapping items

JS array = number assignment changes by one, causing the problem of changing the original array

【Jailhouse 文章】Base Architectures for virtual-physical computing(2018)

Case ---- how efficient is the buffer stream compared with the ordinary input stream and output stream?

Easy to understand: basic knowledge of MOS tube

Download and run the C open source control metroframework demo project

In depth analysis: is the hottest business model in 2022 linked by 2+1 a legal model?

VSCode 如何开启多个终端?如何横向显示?
随机推荐
What determines the "personality" of AI robots?
Common mode inductance has been heard many times, but what principle do you really understand?
MFC IniFile Unicode mode reading method
target_compile_features specified unknown feature “cxx_std_14“ for target
DOM event type
Pic16f877xa instruction system (assembly language)
【datawhale202207】强化学习:策略梯度和近端策略优化
Do you know the same period last year in powerbi
Brief tutorial of vbs script syntax (1)
Review of some classic exercises of arrays
【C】 Program environment and pretreatment
Mlx90640 infrared thermal imager temperature measurement module development notes (I)
Some interview questions collected
SAP FICO section III BDC and ltmc import S4 financial account
GIS实战应用案例100篇(十七)-基于DEM制作三维地图
Developers must read: 2022 mobile application operation growth insight white paper
R strange grammar summary
VSCode 如何开启多个终端?如何横向显示?
C#读取倍福Beckhoff变量
The code spell checker plug-in avoids some specific vocabulary errors "XXX": unknown word.cspell