comparefn. The comparefn function must accept two parameters: element1 and element2. If you want element1 to be placed before element2, a negative number is returned. If you want element1 to be placed after element2, a positive number is returned, if the two numbers are treated equally (that is, the original order is maintained), 0 is returned. When comparefn is omitted, the elements are arranged alphabetically. For example, for the defined comparison function cmp: function cmp (e1, e2) {return
example:
Example 1:
Var oldArr = [1, 2, 3];
Alert (oldArr. push (4, [5, 6])-> 5 (here we will only calculate [5, 6] as an element, and return the updated array length of 5)
In this case, oldArr-> [1, 2, 3, 4, [5, 6]
Alert (oldArr. pop ()-> [5, 6] (the last element [5, 6] is displayed here, instead of 6)
In this case, oldArr-> [1, 2, 3, 4]
OldArr. pop ()-> 4
OldArr. pop ()-> 3
OldArr. pop ()-> 2
OldArr. pop ()-> 1
OldArr. pop ()-> undefined (empty array pop-up)
Now let's take a look at unshift
and shift.Both of these methods are performed on the head of the array, while others are similar to push and pop, but the Unshift method in IE returns the undefinedExample 2:var oldarr2=[1,2];Oldarr2.unshift (3) –>undefinedAt this time OLDARR2 is –>[3,1,2]Oldarr2.shift () –>3At this point oldArr2 is []Next, take a look at the powerful splice, which can be used to add, delete, and manipulate elements at random positions in the originalModify on ArrayS
(oldArr. pop ()-> [5, 6] (the last element [5, 6] is displayed here, instead of 6)In this case, oldArr-> [1, 2, 3, 4]OldArr. pop ()-> 4OldArr. pop ()-> 3OldArr. pop ()-> 2OldArr. pop ()-> 1OldArr. pop ()-> undefined (empty array pop-up)Now let's take a look at unshift and shift after talking about push and pop.Both methods are performed through the operation on the array header. Other methods are similar to push and pop. However, in IE, The unshift method returns undefined.
Example 2:Var oldArr
and shift.Both of these methods are performed on the head of the array, while others are similar to push and pop, but the Unshift method in IE returns the undefinedExample 2:var oldarr2=[1,2];Oldarr2.unshift (3) –>undefinedAt this time OLDARR2 is –>[3,1,2]Oldarr2.shift () –>3At this point oldArr2 is []Next, take a look at the powerful splice, which can be used to add, delete, and manipulate elements at random positions in the originalThe start of the
)at this time oldarr–>[1,2,3,4]Oldarr.pop () –>4Oldarr.pop () –>3Oldarr.pop () –>2Oldarr.pop () –>1Oldarr.pop () –>undefined (empty array popup)now finish the push and pop and take a look at Unshift and shift .Both of These methods are performed on the head of the array, while others are similar to push and pop, but the Unshift method in IE returns the undefined Example 2:var oldarr2=[1,2];Oldarr2.unshift (3) –>undefinedat this time OLDARR2 is –>[3,1,2]oldarr2.shift () –>3at this point oldArr2 i
size comparison function defined by comparefn. The comparefn function must accept two parameters: element1 and element2. If you want element1 to be placed before element2, a negative number is returned. If you want element1 to be placed after element2, a positive number is returned, if the two numbers are treated equally (that is, the original order is maintained), 0 is returned. When comparefn is omitted, the elements are arranged alphabetically. For example, for the defined comparison functio
oldarr–>[1,2,3,4]Oldarr.pop () –>4Oldarr.pop () –>3Oldarr.pop () –>2Oldarr.pop () –>1Oldarr.pop () –>undefined (empty array popup)Now let's talk about push and pop and see Unshift and shift.Both methods are operated through the head of an array, others are similar to push and pop, but in IE the Unshift method returns the undefinedExample 2:var oldarr2=[1,2];Oldarr2.unshift (3) –>undefinedAt this time oldArr2 for –>[3,1,2]Oldarr2.shift () –>3At this point oldArr2 is [1,2]Next, look at the powerf
Adding elements to the arrayThe push () method can add one or more array items to the end of the list:var arr = [];arr.push (' A ', ' B '); Console.log (arr); [' A ', ' B '] The Unshift () method adds one or more array items to the front of the arrays:var arr = [' A ', ' B '];arr.unshift (n); Console.log (arr); [1, 2, "a", "B"]The splice () method adds an array entry to the array:var arr = [' A ', ' B ', ' C ', 1,2];arr.splice (2,0, ' d ', ' C ', ' e
This article describes how to delete array elements in javascript and how to clear arrays, for more information about how to delete array elements and clear arrays, see the next article.
Simple Method for deleting array elements and clearing arrays using javascript
I. Clear the Array
Var ary = [1, 2, 4]; ary. splice (0, ary. length); // clear the array console. log (ary); // output [], empty array, which is cleared
Ii. Delete array elements
Var ar
Push (args) can press multiple elements at a time and return the updated array length.var oldarr=[1,2,3];Alert (Oldarr.push (4,[5,6])) –>5 (this only evaluates [5,6] as an element, returning the updated array length 5)At this time oldarr–>[1,2,3,4,[5,6]]The pop () function only pops the last element at the end and returns the element that pops up and returns undefined if it is called pop () for the number of empty groups.Alert (Oldarr.pop ()) –>[5,6] (this pops up the last element [5,6] instead
VaR arr = ['A', 'B', 'C'];To delete 'B', you can use either of the following methods:1. Delete method: delete arr [1]In this way, the length of the array remains unchanged. In this case, the ARR [1] is changed to undefined, but the index of the original array remains unchanged. In this case, you need to traverse the array element before using it.For (index in ARR)Document. Write ('Arr ['+ index +'] = '+ arr [Index]);This Traversal method skips the undefined element.* Ie4.o is supported later.2.
transmitted bytes.
If the call is successful, the number of transmitted bytes is returned. If the call fails, the value is-1, and errno is set.Note: The man Manual states that in_fd must be a file descriptor that supports functions similar to mmap,
That is, it must point to a real file.And the out_fd must be a socket. It can be seen that sendfile is designed for transferring files over the network.
// Use the sendfile function to transmit the file # include
); // [1, 2, 3]Console. log (a. length); // 3
Queue Method
Since the stack method has been implemented, how can we reduce the number of first-in-first-out queues? shift can delete the minimum element of the array index and reduce the index of the subsequent elements by one, while length is also reduced by one, in this way, shift/push can be used to simulate the queue. Of course, there is an unshift method corresponding to the shift method, which is used to add an element to the array header.
Javascript array operation function summary, javascript Array Function
In fact, usually a lot of push and pop should be used, but it should be noted down for later use.
Shift: Delete the first entry of the original array and return the value of the deleted element. If the array is empty, undefined is returned.
Copy codeThe Code is as follows:Var a = [1, 2, 3, 4, 5];Var B = a. shift (); // a: [2, 3, 4, 5] B: 1
Unshift: Add the parameter to the beginning of the original array and return the length
This article mainly summarizes and introduces Javascript array operation functions. For more information, see push and pop, which are usually used, for later use.
Shift: Delete the first entry of the original array and return the value of the deleted element. If the array is empty, undefined is returned.
The Code is as follows:
Var a = [1, 2, 3, 4, 5];Var B = a. shift (); // a: [2, 3, 4, 5] B: 1
Unshift: Add the parameter to the beginning of the original array and return the length of the ar
parameter) is default, the result is always returned until the end of the array. If the parameter is negative, it is truncated from the back to the front. Remember that this function is used to create a new array. Well.
[Cc lang = 'javascript ']// All operations are performed on the original arrayVar arr = [1, 2, 3, 4, 5, 6, 7, 8];
Arr. slice (); // If the array element starts from 0, it returns the intermediate element from the first to the third: [2, 3]Alert (arr. join (); // [1, 2, 3, 4, 5,
-dimensional arrays, which are not discussed here.
Attribute of the array: lengthArr. length returns the length of the array arr, which is common in traversing arrays in a loop. For example:For (var I = 0; I Execution part}
Access to array elements: arr [index], where index indicates the base number of the array. It starts from 0 and has a total of arr. length element. for example, if arr [0] accesses the first array element, arr [1] accesses the second array element .... operation Methods of ar
as transmission media: 100Base-TX, 100Base-T2, and 100Base-T4. Among them: 100Base-T4 standard requires the use of all 4 pairs of lines for signal transmission, the other two standards only require 2 pairs of lines. The 100Base-TX standard is the most popular in Fast Ethernet. Therefore, when purchasing a m twisted pair, do not use a twisted pair with only two wires at a low cost. Category 3, category 4, Category 5, and Category 5 twisted pair wires are defined as 4 pairs in the US cable standa
. Currently, Category 5 wires are more than Category 6 wires. The 3rd class line is commonly used for 10 Mbps Ethernet data and voice transmission in the LAN, and complies with the IEEE 10Base-T standard. 5th twisted pair wires currently have the largest LAN market, with a maximum rate of 100 Mbps, in line with the IEEE 3u 100Base-TX standard.
The main difference between Category 5 and Category 5 is the application. Only two pairs of cables are used for transmission during use of Category 5 cab
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.