当前位置:网站首页>Array method in JS 2021.09.18
Array method in JS 2021.09.18
2022-06-28 11:30:00 【Little dream of becoming a big man】
Basic data type :number、string、boolean、undefined、null
quote ( complex ) data type :Array、function, Object
Conclusion : Simple types store the value itself , Complex types store addresses , If you assign the first object to another variable , At this point, the two variables will point to the same object .
Stack memory : Storage address ; Heap memory : Store the value pointed to by the address ;
Different types of data Compare Conversion required . Specific rules See the table below :
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Equality_comparisons_and_sameness#%E4%B8%A5%E6%A0%BC%E7%9B%B8%E7%AD%89

Methods of array operation :
splice : Delete or add elements anywhere in the array
splice(start, deletedCount) Remove elements
splice(start, deletedCount , item) Delete + add to , The third parameter is to add several new elements to the original deleted position
splice(start, 0 , item) Is to add a new element at a certain position
array.push( Elements );// Add elements from behind , Returns the of the new array length
array.pop();// Remove elements from the back of the array , Return the deleted element
array.unshift( Elements );// Add elements from the front of the array , Returns the length of the new array
array.shift();// Remove the element from the front of the array , Return the deleted element
-- All that is added is the return length
-- All the deleted elements are returned to the deleted elements
Array splicing :concat: Array merge , It will not affect the original array , Will return a new array .
Sort of array :array.sort(); // Sort of array , The default in accordance with the Letter / First character Order
Inversion of array :array.reverse(); // Flip array
Array and string conversion :array.join( Separator ) // effect : Concatenate the values of the array into strings , And return string
split: Split a string into arrays ( Very often )
New array method :
indexOf Find the position where an element first appears in the array ;
grammar :arr.indexOf( Elements ,[ The starting subscript of the start search ]); # Return value : If you find it , Just return the subscript of this element in the array , If not found , Just go back to -1;
lastIndexOf( value ) Get the last position of the corresponding subscript through the value of the array
every(function( value , Subscript , Array ){}) Determine whether each value in the array meets the requirements
some(function( value , Subscript , Array ){}) Determine whether at least one value in the array meets the requirements
forEach For traversing arrays ; This method does not return a value , Pure read operation , It will not change the value of the original array .
grammar :
arr.forEach(function( value , Subscript , Current array ){
// Code segment
});
var arr = ['a', 'b', 'c'];
// forEach Yes 2 Parameters :
// callback : Support 3 Parameters
// thisArg : Specifies the name of the callback function this Point to
arr.forEach(function callback(item, index, arr) {
console.log(this == arr); // true
console.log(item, index);
}, arr);

map Traversal array , And pass each element back to the function for processing , Return a new array ,.( This method is mainly used to process each value in the array with the same rules , And form a new array to return )
grammar :
arr.map(function( value , Subscript , Current array ){
// Yes v Process and return each after processing v Array of components
});
// map Also comes with traversal , During traversal You need to return a new value As an element in the new array
var newArr = arr.map(function (item, index, arr) {
// Callback function Return value required
// return 1;
// Based on the original value modify , Returns the new value
return item.toUpperCase();
});
console.log(newArr);
filter Traversal array , According to the filter conditions , Filter out the elements that meet the conditions in the array , Form a new array and return .( The use method and function are the same as map Methods like , But the running rules are different .map Functions in methods , Used to return a new element , and filter Functions in methods , According to return true or false To filter elements )
grammar :
arr.filter(function( value , Subscript , Current array ){
// filter
});
reduce Merger , Where the call back function , There are two arguments in the fallback function , The first parameter is the return value of the last operation , The second parameter is from the second element to the last element .
grammar :
arr.reduce(function(prev,next){
// Logic code
});
Common pseudo arrays :arguments、nodeList、htmlCollection
Bubble sort
Compare two adjacent elements , Use a loop to arrange the numbers in an array in ascending or descending order .
Selection sort
Descending : First find the maximum value , On the far left , Find the second largest value , To the left ..., Already arranged , No longer participate in the comparison
边栏推荐
- QML控件类型:TabBar
- 100 important knowledge points that SQL must master: retrieving data
- Gee: mcd64a1 based globfire daily fire data set
- 实体转JSON时,值为null的字段的丢失问题
- Day39 prototype chain and page Fireworks Effect 2021.10.13
- 网页提示此站点不安全解决方案
- Graduation season, some suggestions for you who are new to the society
- 远程登录sshd服务
- JS foundation 3
- 什么是DAPP系统发展与解析理解
猜你喜欢

Class pattern and syntax in JS 2021.11.10

Day39 prototype chain and page fireworks effect 2021.10.13

字符串 & 堆 & 方法区

零基础自学SQL课程 | IF函数

Solve the problem of reading package listsdonebuilding dependency treereading state informationdone

Redis6 一:Nosql引入、Redis可以解决什么问题?

远程登录sshd服务

携手Cigent:群联为SSD主控固件引入高级网络安全防护特性

Recommended practice sharing of Zhilian recruitment based on Nebula graph

科研丨Web of Science检索技巧
随机推荐
论文阅读 (59):Keyword-Based Diverse Image Retrieval with Variational Multiple Instance Graph
Everyone can participate in open source! Here comes the most important developer activity in dragon lizard community
Recommended practice sharing of Zhilian recruitment based on Nebula graph
JS基础2
JS基础8
网页提示此站点不安全解决方案
合约量化交易系统开发 | 合约量化APP开发(现成案例)
[sword finger offer] 49 Ugly number
Compareto() and equals() methods of BigDecimal class
Makefile introduction
科研丨Web of Science检索技巧
零基础自学SQL课程 | IF函数
工作组环境下的内网渗透:一些基础打法
Word、PDF、TXT文件实现全文内容检索需要用什么方法?
无法重新声明块范围变量
[sciter]: how sciter uses i18 to realize multi language switching of desktop applications and its advantages and disadvantages
Jetpack Compose Desktop 桌面版本的打包和发布应用
合约量化系统开发(搭建讲解)丨合约量化系统开发(源码解析及现成案例)
基于验证码识别的机器学习项目captcha_trainer操作实践
JS基础1-JS引入与运算符