Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
JavaScript is an ‘object-oriented’ programming language that contains objects such as document document objects, String String objects, Array Array objects, window objects, and Form objects. You can use JavaScript to enrich and animate your programs.
Array as a common data structure to deal with in the work, need to master. Today we have learned the common methods of array, here is the summary:
Learn the common operation method of array
To define an array
An array is one of the most important data structures in JavaScript. An array is a container that contains all types of data. Half of the array contains all types of data, such as objects. If you store a numeric numeric array. , etc.
Here are the methods to declare an array. The simplest is the constant definition method, which assigns an empty array []. And other methods
const myArr = []
const myNewArr = new Array(a)const myNewArr1 = new Array(5) // An array of length 5
Copy the code
Array traversal
Arrays can be used for or for… In traverses, looping over each element
Common operations on arrays
-
Push () adds one or more elements to the end of an array Returns the new length value of the array
-
Splice () splice(start): deletes numbers from the start position all the way to the end of the array
-
Pop () deletes the end of the array one at a time No arguments return the deleted element
-
Unshift () adds one or more elements to the head of an array
-
Shift () removes the element in the array header
Of course, there are other ways, follow up, practice