当前位置:网站首页>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
边栏推荐
- Summary of spatial temporal time series prediction modeling methods
- Introduction to GDB
- JS foundation 5
- js中的数组方法 2021.09.18
- Which broker is safer and more convenient to open an account for Oriental Fortune mobile stock?
- 毕业季,给初入社会的你一些建议
- 合约量化系统开发(搭建讲解)丨合约量化系统开发(源码解析及现成案例)
- 基于验证码识别的机器学习项目captcha_trainer操作实践
- Day39 prototype chain and page fireworks effect 2021.10.13
- Yann Lecun's new paper: the road to building automatic agents
猜你喜欢

Tidb v6.0.0 (DMR): initial test of cache table - tidb Book rush

js中this的默认指向及如何修改指向 2021.11.09

Packaging and publishing application of jetpack compose desktop version

day39 原型鏈及頁面烟花效果 2021.10.13

人人都可以参与开源!龙蜥社区最不容错过的开发者活动来了

day36 js笔记 ECMA6语法 2021.10.09

智联招聘基于 Nebula Graph 的推荐实践分享

Solve the problem of reading package listsdonebuilding dependency treereading state informationdone

功能真花哨,价格真便宜!长安全新SUV真实力到底怎样?

js中的class类模式及语法 2021.11.10
随机推荐
setInterval、setTimeout和requestAnimationFrame
This Exception was thrown from a job compiled with Burst, which has limited exception support. 报错
QML控件类型:TabBar
【剑指Offer】49. 丑数
使用ssm项目对Mysql8进行访问的时候,出现连接失败和一些错误的解决办法
Setinterval, setTimeout and requestanimationframe
远程登录sshd服务
js中的class类模式及语法 2021.11.10
Introduction to GDB
Join hands with cigent: group alliance introduces advanced network security protection features for SSD master firmware
Packaging and publishing application of jetpack compose desktop version
李宏毅《机器学习》丨7. Conclusion(总结)
关于Pytorch中双向LSTM的输出表示问题
QML control type: tabbar
day39 原型链及页面烟花效果 2021.10.13
Class pattern and syntax in JS 2021.11.10
mysql-.sql文件钓鱼上线
智联招聘基于 Nebula Graph 的推荐实践分享
元宇宙系统的发展与原理介绍
JS foundation 3