Summary and analysis of JavaScript array methods_javascript skills
Since I have been coding on freecodecamp recently and used a lot of JavaScript array methods, I made a compilation of JavaScript tutorials. The specific content is as follows:
1. Ordinary method
1. join() joins array elements together and returns them in string form
Parameter: Optional, specifies the separator between elements. If there is no parameter, it defaults to comma
Return value: string
Impact on original array: None
2. reverse() changes the order of the elements of the array into reverse order and returns
Parameters: None
Return value: array
Impact on the original array: The original array is modified into an array arranged in reverse order
3. sort() sorts the array elements and returns
Parameters: optional, sorting method function, without parameters, the default is to sort in dictionary order
Return value: sorted array
Impact on the original array: The original array is modified into a sorted array
4. concat() connects several arrays
Parameters: several, which can be arrays or elements,
Return value: New array after concatenation
Impact on original array: None
5. slice() cuts out several elements from the array, forms a new array and returns
Parameters: two numbers, the second of which is optional. The first parameter indicates the index value of the first element to be intercepted (this element is included when intercepting). If the first parameter is a negative number, it means that the intercepted element starts from Counting from the end of the element (for example: -1 means the last element); the meaning of the second parameter is the index value of the element to stop intercepting (this character is not included when intercepting), the negative value is the same as the first parameter
Return value: intercepted new array
Impact on original array: None
6. splice() replaces, deletes or inserts elements from the array and returns a new array
Parameters: Several parameters, of which the first parameter is required and the others are optional. The first parameter is the first index value of the operation. If there is no second parameter at this time, the first parameter (including the first parameter) will be deleted. All elements after the index value of each parameter), when the second parameter is included, the second parameter deletes the number of elements and returns a new array composed of these elements; when the second parameter is 0, the following parameters will Insert the original array as a new element and return an empty array; when the second parameter is not 0 and contains other parameters, the replacement operation is performed and the new array composed of the original elements before replacement is returned
Return value: new array composed of deleted elements
Impact on the original array: Replacement, deletion, insertion, etc. operations will be performed on the original array
7. push() adds elements to the end of the array and returns the array length
Parameters: several, elements added to the end of the array
Return value: length of the array after adding elements
Impact on the original array: elements
8. pop() deletes an element from the end of the array
Parameters: None
Return value: deleted element
Impact on the original array: One element is deleted from the end of the original array
9. unshift() adds elements to the head of the array and returns the array length
Parameters: several, elements added to the head of the array
Return value: length of the array after adding elements
Impact on the original array: elements
10. shift() deletes an element from the head of the array
Parameters: None
Return value: deleted element
Impact on the original array: One element is deleted from the head of the original array
11. toString() converts the array into a string, with commas separating each element
Parameters: None
Return value: The formed string (in a two-dimensional array, only the elements of the two-dimensional array are connected)
Impact on original array: None
12. toLocaleString() is the localized version of toString() method
-------------------------------------------------- ----------------------------------
2. Iterator method
1. foreach() calls the method on each element of the array
Parameters: a function
Return value: None
Impact on original array: None
2. every() accepts a function whose return value is Boolean type. If the function returns true for all elements in the array, it will return true, otherwise it will return false
Parameters: a function whose return value is Boolean
Return value: true or false
Impact on original array: None
3. some() accepts a function with a return value of Boolean type. As long as there are elements in the array, the function returns true, otherwise it returns false
Parameters: a function whose return value is Boolean
Return value: true or false
Impact on original array: None
4. map() accepts a function as a parameter and returns a new array. The elements of the new array are the results of using the function on the original array elements
Parameters: a function
Return value: an array composed of each element using the result value of the function
Impact on original array: None
5、filter()接收一個傳回值為布林值的函數作為參數,對所有元素應該該函數,並傳回傳回值為true的元素組成的新陣列
參數:一個函數
傳回值:每個元素使用函數為true的元素組成的陣列
對原數組的影響:無
-------------------------------------------------- ------------------------------
三、歸併方法
1、reduce()接受一個函數作為參數,並傳回一個值。從一個累加值開始, 不斷對累加值和陣列中的後續元素呼叫函數。
參數:一個函數
傳回值:最後的累加值
對原數組的影響:無
2、reduceRight()方法
說明:和reduce一樣,只是執行順序是從右到左
以上這篇JavaScript陣列方法總結分析就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service
