Introduction to JavaScript 8

Explore innovative ideas for Australia Database development.
Post Reply
aminaas1575
Posts: 325
Joined: Sun Dec 22, 2024 4:03 am

Introduction to JavaScript 8

Post by aminaas1575 »

Finally, the array is empty. The first line assigns the a array to be an empty array. The second line inserts the value of element 1 into the a array, so the a array will become [1], and the returned value is 1 (after inserting the value of element 1 The array length is 1), the third line adds element 22 to the front end of the a array, so the a array will become [22,1], at this time the array length is 2, so the return value of the unshift function is 2, the fourth line Take out the frontmost element of array a, so the element 22 put in the third row will be taken out, and the returned value is 22.

Because the frontmost element of array a is taken out, the current array a will become [1], and the value returned is 22. Wu Xing adds two elements 3,[4,5] to the front of array a, one is a simple value 3, and the belarus whatsapp phone number other is an array [4,5]. At this time, it can be seen that when the unshift function adds multiple elements at a time The order will be consistent with the input, so the order of elements added at one time is 3 and [4,5]. At this time, array a will insert elements 3 and [4,5] at the front of the array, so array a will become [3, [4,5],1], because two elements (3 and [4,5]) are inserted at one time, the length of the array becomes 3.

The sixth line outputs the frontmost element of the a array, so the fifth line puts Element 3 of will be taken out, and the returned value is 3. Because the frontmost element of the current a array has been taken out, it will become [[4,5],1]. The seventh line shows the frontmost element of the a array. , so the element [4,5] put in the fifth line will be taken out, and the returned value is [4,5]. The current a array will become [1] because the frontmost element has been taken out, and finally The frontmost element of the a array is taken out line by line, so the element 1 put in the second line will be taken out, and the return value is 1. Because the frontmost element of the a array is taken out, the current a array will become [].
Post Reply