当前位置:网站首页>[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>边栏推荐
- Some common interview questions about IO stream and string
- Data too long for column 'data' at row 1 and the garbled code caused by setting to longblob are solved. node-mysql
- Keilc51 usage details (III)
- How programmers write bugs
- Use of golang exec.command
- C control open source library: download of metroframework
- HTX00001_ Keil51 bug encountered in serial port parsing
- Mysql database backup and recovery
- Req.body in node.express is always undefind
- Machine learning keras fitting sine function
猜你喜欢

容器内组播

Restrict Su command and sudo mechanism to promote nmap and console command netstat

Common mode inductance has been heard many times, but what principle do you really understand?

C # --metroframework framework calls the metromodernui library and uses it in the toolbar

R strange grammar summary
![[sword finger offer] analog implementation ATOI](/img/01/76a3b1fcc6403368a363146d553777.png)
[sword finger offer] analog implementation ATOI

labelme标注不同物体显示不同颜色以及批量转换

Special episode of Goddess Festival | exclusive interview with Chinese AI goddess Zhang Qingqing's transformation from a female learning tyrant to a female entrepreneur

Evolution of coupon architecture under C2B mode

Create a new STM32 project and configure it - based on registers
随机推荐
JSON、
Health clock in daily reminder tired? Then let automation help you -- hiflow, application connection automation assistant
Quick sort code implementation
【剑指Offer】模拟实现atoi
Over adapter mode
Dry goods | training AI model can't find data? Collect 20 selected open source communities!
[datawhale202207] reinforcement learning: strategy gradient and near end strategy optimization
MFC IniFile Unicode mode reading method
Req.body in node.express is always undefind
A little consideration of strategic mode
【transformer】DeiT
100 GIS practical application cases (seventeen) - making 3D map based on DEM
Multithreading programming under Win32 API
C language -c51 compilation warning "* * * warning l1: unresolved external symbol" and extern
What does PK, NN, Qu, B, UN, ZF, AI, G mean when creating tables in MySQL
How does vscode enable multiple terminals? How to display horizontally?
Review of some classic exercises of arrays
长安链双花交易防范策略
Developers must read: 2022 mobile application operation growth insight white paper
What does "TTL" mean in domain name resolution?