当前位置:网站首页>[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>边栏推荐
- 杜教筛
- JZ7 重建二叉树
- What determines the "personality" of AI robots?
- Developers must read: 2022 mobile application operation growth insight white paper
- 百度希壤首场元宇宙拍卖落槌,陈丹青六幅版画作品全部成交!
- Prevention strategy of Chang'an chain Shuanghua transaction
- What does PK, NN, Qu, B, UN, ZF, AI, G mean when creating tables in MySQL
- 【C语言】指针和数组的深入理解(第一期)
- JSON、
- Ida Pro novice tutorial
猜你喜欢

Observer mode
![[C language] in depth understanding of pointers and arrays (phase I)](/img/4b/26cf10baa29eeff08101dcbbb673a2.png)
[C language] in depth understanding of pointers and arrays (phase I)

Download and run the C open source control metroframework demo project

ARM裸板调试之JTAG调试源码级调试

共模电感听过很多次,但是什么原理你们真的懂吗?

百度希壤首场元宇宙拍卖落槌,陈丹青六幅版画作品全部成交!

Use abp Zero builds a third-party login module (III): web side development

Easy to understand: basic knowledge of MOS tube

Baidu xirang's first yuan universe auction ended, and Chen Danqing's six printmaking works were all sold!
![[C language] program environment and preprocessing](/img/d6/d59a0d8d286ea9408043d8ad1e1348.png)
[C language] program environment and preprocessing
随机推荐
Detailed annotation and analysis of start.s of uboot
Scientific computing library numpy Foundation & Improvement (Understanding + explanation of important functions)
C#读取倍福Beckhoff变量
[jailhouse article] base architectures for virtual physical computing (2018)
The most comprehensive multi-threaded application tutorial - summary in detail
DOM event type
In container multicast
Function template learning record
What does PK, NN, Qu, B, UN, ZF, AI, G mean when creating tables in MySQL
【Unity3D】UGUI回调函数
Application of first-order complementary filtering to STM32 ADC acquisition
Do you know the same period last year in powerbi
Baidu SEM bidding avoidance
RecycleView实现item重叠水平滑动
[cann training camp] play with the one-stop plan of cann target detection and recognition - learning notes 1 (initial experience)
[unity3d] ugui callback function
机器学习 Keras拟合正弦函数
Vbs script COM object extension and use (3)
C language -c51 compilation warning "* * * warning l1: unresolved external symbol" and extern
【luogu P6629】字符串(Runs)(树状数组)