Detailed introduction to arrays in javaScript
Create array
var a=[1,2,3,4]
var arr=new Array()
## var arr=new Array(10);//Create an array with a length of 10
var arr =new Array(1,2,3,4,5,6);//Create an array
arr.length==6;
Delete array delete var a=[1,2,3];
delete a[0];
1 in a //false,
Array traversal
##for/in forEach var a=[1,2,3];
var b=0;
a. forEach(function(x){
## b+=x;//Add
})
Array methods
Array.jion();//Convert all elements to strings and concatenate them together, default comma Connection, there is a parameter, you can modify the connection style
Array.reverse();//Reverse sort the array
Array.sort(); // Sort the array and return the sorted array. If there are no parameters, the default alphabetical order will be used. If there are parameters, the order will be confirmed based on the return value of the callback function.
var a=[33,4,1111,222]; a.sort();//1111,222,33,4;
a.sort(function(a,b){
return a-b;//4,33,222,1111
});
a.sort(function(){
return b-a;//1111,222,33,4
})
Array.concat();//Concatenate arrays
var a=[1,2,3];
a.concat(4,5);//[1,2,3,4,5] a.concat([ 4,5]);//[1,2,3,4,5]
a.concat([4,5],[6,7]);// [1,2,3,4,5,6,7]
a.concat([4,[5,[6,7]);//[1,2 ,3,4,5,[6,7]]
Array.slice(); returns a fragment of the specified array
var a=[1,2,3,4,5];
## a .slice(0,3);//[1,2,3,4];
## a.slice(3);//[4,5];
## a.slice(1,-1);//[2,3,4];
# a.slice(-3,-2);//[3]
# Array.splice() ;splice() will modify the array. The first parameter is the starting point, the second parameter is the number of deleted items, and the subsequent parameters are the inserted elements. The starting point of the inserted elements is the first parameter. Note that the inserted array is an array. Itself, not the elements inside Array.push( ) and Array.pop(); push adds elements at the end, pop deletes elements at the end, and modifies the original array ## ##Array.unshift() and Array.shift(); unshift adds elements to the head, shift deletes elements to the head, and modifies the original array Array.toString() and Array.toLocalString(); convert to string #Array methods in ES5 forEach() method Map() method ##var a=[1,2,3]; b=a.map(function(x){ return x*x;//b is [1,4,9] })
## Filter() ## var a=[5,4,3,2,1]; b=a.filter(function(x){ Return x<3;//[2,1] ## }) ## var a=[5,4,3,2,1];## b=a.filter(function(x,i){ Return i%2==0;//[5,3,1], i is the second parameter of filter, it represents the subscript of the array, and there is a third parameter The current element belongs to the object of the array ## }) ## every() and some(); are logical judgments of the array ## ## b=a.every(function(x){ return x<10;// true; }) var a=[5,4,3,2,1];## b=a .some(function(x){ reduce() and reduceRight() var a=[5,4,3,2,1];# b=a.reduce(function(x,y){ return x+y;//Array summation b=a.reduce(function(x,y){ ## return x*y;//Array multiplication },1) ## b=a.reduce(function(x,y){ Return x>y?x:y;//Find the minimum value },1) reduce()//Two parameters, the first parameter executes the function, the second parameter Optional initial value. When the function is executed for the first time, the initial value is used as the first parameter of the function. The value returned by subsequent executions of the function is used as the first parameter of the function. indexOf() and lastindexOf; search for the specified element of the array, if found return the subscript, if not found return -1 Type of array ## Array.isArray([]);/ /true Array.isArray([]);//false
reduceRight() and Like reduce(), execution starts from the last element
The above is the detailed content of Detailed introduction to arrays in javaScript. For more information, please follow other related articles on the PHP Chinese website!

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 delete Xiaohongshu notes? Notes can be edited in the Xiaohongshu APP. Most users don’t know how to delete Xiaohongshu notes. Next, the editor brings users pictures and texts on how to delete Xiaohongshu notes. Tutorial, interested users come and take a look! Xiaohongshu usage tutorial How to delete Xiaohongshu notes 1. First open the Xiaohongshu APP and enter the main page, select [Me] in the lower right corner to enter the special area; 2. Then in the My area, click on the note page shown in the picture below , select the note you want to delete; 3. Enter the note page, click [three dots] in the upper right corner; 4. Finally, the function bar will expand at the bottom, click [Delete] to complete.

As a Xiaohongshu user, we have all encountered the situation where published notes suddenly disappeared, which is undoubtedly confusing and worrying. In this case, what should we do? This article will focus on the topic of "What to do if the notes published by Xiaohongshu are missing" and give you a detailed answer. 1. What should I do if the notes published by Xiaohongshu are missing? First, don't panic. If you find that your notes are missing, staying calm is key and don't panic. This may be caused by platform system failure or operational errors. Checking release records is easy. Just open the Xiaohongshu App and click "Me" → "Publish" → "All Publications" to view your own publishing records. Here you can easily find previously published notes. 3.Repost. If found

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.

How to add product links in notes in Xiaohongshu? In the Xiaohongshu app, users can not only browse various contents but also shop, so there is a lot of content about shopping recommendations and good product sharing in this app. If If you are an expert on this app, you can also share some shopping experiences, find merchants for cooperation, add links in notes, etc. Many people are willing to use this app for shopping, because it is not only convenient, but also has many Experts will make some recommendations. You can browse interesting content and see if there are any clothing products that suit you. Let’s take a look at how to add product links to notes! How to add product links to Xiaohongshu Notes Open the app on the desktop of your mobile phone. Click on the app homepage

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

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

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese
