First, the definition of the array and the method of initialization:
var myArray = new Array(1,3.1415,"love"); //Note here that the elements in the myArray array are not just elements of the same data type. They can have integers and integers. Floating point types, strings, etc. are all acceptable. This fully demonstrates the weakening of data types by JavaScript as a language, and the language is more casual and simplified. Just use var when defining an object.
The introduction here is limited, and there are some that I have not given the results. I hope you can experience it yourself and try it yourself to see what the results are. This will help with memory. The following parameters with [] can be omitted.
Attributes of Array:
length: The length of the array object, that is, the number of array elements. It should also be noted here that the subscript of the first element is 0.
document.write(myArray.length); //The result is 3
Array method:
join(): Connect the elements in the array one by one, separated by The symbol is placed between elements
document.write(myArray.join("-")); //Output result: 1-3.1415-love
document.write(myArray.join(" ")) ; //Output result: What is it?
document.write(myArray.join("*¥")); //Output result: What is it?
document.write(myArray.join("* &")); //Output result: What is it?
document.write(myArray.join(" ")); //Output result: What is it?
reverse(): Reverse the order of elements in the array
document.write(myArray.reverse()); //Output result: love,3.1415,1
slice([,]): Equivalent to array clipping, the end is not included here. When you see this, you should think of the substring() and substr() methods of the Sting object. . In fact, they are all similar.
var arraynumber = new Array(1,2,3,4,5,6,7,8);
document.write(arraynumber.slice(3)); //Output result: 4,5, 6,7,8
document.write(arraynumber.slice(3,5)); // Output result: 4,5
i made a mistake, the result I originally wrote was 4,5,6, Actually it's 4,5. Thanks to a friend for bringing this up. Please note that the slice method does not include the termination position.
document.write(arraynumber.slice(3,3)); // Output result: What is it?
document.write(arraynumber.slice(3,2)); // Output result: What is it?
document.write(arraynumber.slice(3,-1)); // Output result: What is it?
document.write(arraynumber.slice(-100)); // Output result: What is it?
sort([
]): Sort
Without method function, sort in alphabetical order, that is, sort according to the order of character encoding, not sorting by numerical value as commonly thought.
If it has a method function, it will be sorted by the method function.
Example:
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31