当前位置:网站首页>JS array (summary)
JS array (summary)
2022-07-28 15:56:00 【PBitW】
List of articles
Like what to introduce Algorithm 、 What is the data structure , I'll stop talking , Go straight to the point
js Array is used in , Namely Call directly API, You don't have to package it yourself
The reason why encapsulation is not needed
- Almost all programming languages Natively supports array types , Because arrays are the simplest memory data structures
- js The array of is not like c Language is the same as the underlying code , Only data types other than those defined can be stored , It won't define how long it is and can't increase by itself
The disadvantages of arrays
- Insert... In the middle position 、 The efficiency of deleting elements is relatively low , Because Move elements
- Array expansion , Some languages need Reapply for more storage space , After assigning all the original values , Remove the original array
Create array

Array methods – Return value
js The array of provides many methods :
Of course, there is something missing :
pop( Delete the last element )-- Return removed items
push( Add element at the end )-- Returns the length of the modified array
shift( Delete first element )– Return removed items , If the array is empty, it returns underfined
unshift( Add an element before the first element )– Returns the length of the array
splice( The most powerful method )– The operation passes different parameters and returns different , It's hard to describe
And some missing higher-order functions , for example :
reduce( Ergodic summation )– Returns the result of the sum
filter( Traversal array , Filter the qualified array elements )– Return the qualified New array
sort( Array From small to large / From big to small array , Letters can also )– Return to the changed Original array
find( Find the first qualified member )– Return array members
fundIndex( Find the first index that matches the member )– Return index value
I won't say more here , You can see it directly :
data structure ( Two ) Array structure of
Higher order function - - Liao Xuefeng
05 vue Which array operations of are responsive
js Array method and its return value ( It is easy to use )
Array method note
One 、toString and valueOf The difference between
toString() and valueOf() All are Object method .toString() Method returns the string that reflects the object .valueOf() Method if any original value exists , It converts the object to its original value by default ; Object is a compound value , Most objects cannot really be represented as an original value , So by default valueOf() Method simply returns the object itself , Instead of returning a raw value .
See my blog here :2021 Yahong interview question 2
toString() and valueOf() The main difference is ,toString() The returned string is , and valueOf() The return is The original object
because undefined and null Not object , So they toString() and valueOf() There are no two methods
The number Number Type of toString() The method can connect Receive conversion base , Returns a numeric value in the form of a string with different base numbers ; and valueOf() Method cannot accept conversion cardinality
Time Date Type of toString() Method String representing time Express ; and valueOf() Method returns from now to 1970 year 1 month 1 Japan 00:00:00 Of the numeric type Number of milliseconds
The object of the package valueOf() Method returns the original value of the wrapper object
Use toString() Method to distinguish between built-in functions and custom functions
Thanks to the author : Rice next door , The article links :https://www.jianshu.com/p/24547d4e565f
Two 、pop|push|shift|unshift
These methods can accept multiple parameters , Add or remove multiple elements at once !
边栏推荐
- Shell编程规范与变量
- Multifunctional mixed signal AI acquisition / switching value di/do acquisition to rs485/232/modbus module
- 德国电信否认加强与华为合作,并称过去3年已缩减与华为的合作
- How to compress and decompress ramdisk.img
- Have you seen the management area decoupling architecture? Can help customers solve big problems
- 如何有效进行回顾会议(上)?
- How to effectively conduct the review meeting (Part 1)?
- Where is the RDS MySQL read-only instance of Alibaba cloud created
- Docker container implements MySQL master-slave replication
- How to quickly access the unified authentication system
猜你喜欢

Multipurpose mixed signal 8ai/4di/do to serial port rs485/232modbus acquisition module ibf30

NTC,PT100热电阻转4-20mA温度信号转换器

Shell编程规范与变量

One channel encoder, two channels Di speed measurement, RS485 serial port connected to one channel do alarm module ibf151

Software architecture and design (x) -- Architecture Technology

Using SYSTEMd to manage services

12V pulse speed measurement to 24V level signal conversion transmitter

分体式测斜探头安装要点及注意事项

Event express | Apache Doris Performance Optimization Practice Series live broadcast course is open at the beginning. You are cordially invited to participate!

Thermistor PT100, NTC to 0-10v/4-20ma converter
随机推荐
Open light input / relay output rs485/232 remote data acquisition IO module ibf70
2021 肯特面试题2
Shell programming specifications and variables
光学雨量计应用降雨量检测
Software architecture and design (II) -- Architecture Model
玩死原型链
How to configure Samba server
Has won Huawei's 8.5 billion yuan screen order? Vicino responded: the customer asked for confidentiality and could not reply!
Solve the problem that the right-click menu "edit with idle" of the 『 py 』 file is invalid or missing
Virturalbox solves the problem of kernel driver
Problem of fetching combinatorial numbers
MLX90640 红外热成像仪测温传感器模块开发笔记(八)
2021 肯特面试题1
分体式测斜探头安装要点及注意事项
Transformation principle of voltage and frequency
如何有效进行回顾会议(上)?
Software architecture and design (VII) -- interactive architecture
光学雨量计对比翻斗式雨量计的优势
Docker实现Redis Cluster(集群)模式 哈希槽分区进行亿级数据存储
Give you a linked list, delete the penultimate node of the linked list, and return the head node of the linked list.