当前位置:网站首页>Common methods of JS array
Common methods of JS array
2022-07-03 05:04:00 【The wind blows and birds fly in the crotch】
reverse Flip
sort Sort
push Add... From the back
unshift Add... From the front
pop Delete... From the back
shift Remove... From the front
indexOf From front to back string index
lastIndexOf String index from back to front
join,toString Convert to string type , It is recommended to use join
concat Become
slice Intercept ( A large array is only a part of a fragment )
splice Delete
How arrays are created ( Get to know )
I can only write it literally
Type of data
Simple data type :number,string,boolean,null,undefined (null It's printed out object)
Composite data type , Complex data type :array,object ( Array is also a special kind of object )
We can't get through typeof To detect whether a data is an array , Use other ways to detect :
1. data instanceof Array true The description is an array
2. Array.isArray( data )true The description is an array
Array add elements
1. push PUSH Add at the back ( The most used )
2. unshift Add... To the front
3. pop Remove the last one
4. shift Remove the first one
sort Method in use , The default is to convert all data into strings , Then press ascii Compare in order
Primacy and primacy comparison
reverse() Flip array
sort(function(a,b){return a - b;})
If you ask bubble sort , --> double for Cyclic writing
Find whether the element is in the array , Position in array ( The first index value ), If not, the return value is -1
indexOf Look back before ( Commonly used )
lastIndexOf Look backwards
indexOf Has two functions
1. You can detect the position of elements in the array
2. You can detect whether there is this element in the array ( duplicate removal )
边栏推荐
- Maximum continuous sub segment sum (dynamic programming, recursive, recursive)
- Market status and development prospect prediction of the global autonomous hybrid underwater glider industry in 2022
- Realize file download through the tag of < a > and customize the file name
- MySQL master-slave configuration
- Celebrate the new year together
- 1086 tree traversals again (25 points)
- Sprintf formatter abnormal exit problem
- "Niuke brush Verilog" part II Verilog advanced challenge
- [XSS bypass - protection strategy] understand the protection strategy and better bypass
- Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
猜你喜欢
Actual combat 8051 drives 8-bit nixie tube
Gbase8s composite index (I)
Analysis of proxy usage of ES6 new feature
Concurrent operation memory interaction
Source insight garbled code solution
JDBC database operation
Gbase8s unique index and non unique index
Uipath practice (08) - selector
leetcode406. Rebuild the queue based on height
Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution
随机推荐
Gbase8s composite index (I)
[develop wechat applet local storage with uni app]
[backtrader source code analysis 4] use Python to rewrite the first function of backtrader: time2num, which improves the efficiency by 2.2 times
Analysis of proxy usage of ES6 new feature
Promise
Shuttle + Alluxio 加速内存Shuffle起飞
I've seen a piece of code in the past. I don't know what I'm doing. I can review it when I have time
On typescript and grammar
Apache MPM model and ab stress test
[batch dos-cmd command - summary and summary] - CMD window setting and operation command - close CMD window and exit CMD environment (exit, exit /b, goto: EOF)
1114 family property (25 points)
Market status and development prospect prediction of the global fire hose industry in 2022
Review the old and know the new: Notes on Data Science
Compile and decompile GCC common instructions
最大连续子段和(动态规划,递归,递推)
C language self-made Games: Sanzi (tic tac toe chess) intelligent chess supplement
并发操作-内存交互操作
Retirement plan fails, 64 year old programmer starts work again
leetcode860. Lemonade change
MediaTek 2023 IC written examination approved in advance (topic)