a negative value (-a) exists in the parameter, it indicates the position a relative to the last element in the array. For example, (-3) indicates the last and third elements to the end. If a negative number is displayed, it is first converted and then determined according to the range rules.It also returns a new array without modifying the original array.
1 2 3 4 5 6 7
Var arr = [1, 2, 4, 5]; Console. log (arr. slice (0, 3); // [1, 2, 3] Console. log (arr); // [1, 2, 3, 4
concat () method can be used to return the attributes of a new array for copying the array.var = [Num14]; var num15 = Num14.concat ([4,5],[6,7]); Alert ("when the parameter is multiple arrays:" +NUM15); // 1,2,3,4,5,6,7 var num16 = num14.concat (4,5); Alert ("when the parameter is non-array:" +NUM16); // 1,2,3,4,52.slice ()Slice () can create a new array based on one or more items in the current array, and return a new array.Slice () can receive one or two parameters, that is, the starting and
arr1 = [' A ', ' B ', ' C ']ARR2 = [' 1 ', ' 2 ', ' 3 ']Inserts the array arr2 into the array arr1 after the second element B;Ideas:Inserting a specific position, we first think of splice, but not directly splice (2, 0, arr2), the result: [' A ', ' B ', [' 1 ', ' 2 ', ' 3 '], ' C '];So how can we put arr2 elements of a splice into the arr1, there is no simple way
array directly.
or var arr=["Paramecium", "Love", "fluffy"];//parentheses can also declare an array object
Of course, like the C language, you can also define 2-D 3-dimensional arrays, which are not discussed here.
Properties of array: length
Arr.length returns the length of the array arr, which is common to the traversal of the arrays in the loop, such as:
for (Var i=0;iExecutive part}
Array element access: Arr[index], in which index represents the array cardinality, from 0, a total of a
(); // a: [2, 3, 4, 5] B: 1 unshift: add the parameter to the beginning of the original array, and return the array length var a = [1, 2, 3, 4, 5]; var B =. unshift (-2,-1); // a: [-2,-,] B: 7 Note: In IE6.0, the returned value is always undefined, in FF2.0, the test return value is 7, so The return value is unreliable. You need to use splice instead of this method when returning the value. Pop: Delete the last entry of the original array and return
The Array. observe () method is used to asynchronously monitor changes in arrays, similar to Object. observe () for objects (). When the value of the array changes, it provides a change stream in the order of occurrence. Similar to Object. observe (), it is triggered by the following list of acceptable change types: [add, update, delete, and splice. The javascript Array. observe () method is used to asynchronously monitor changes in arrays.
Observe (
: the returned array contains the element specified by the first parameter and the element starting from the element specified by the second parameter, but does not contain the element specified by the second parameter.
document.write("h.slice(4,5)="+h.slice(4,5));document.write("h.slice(5,9)="+h.slice(5,9))
The splice () method is a common method for inserting or deleting array elements. The first parameter of the
, 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 array.Var a = [1, 2, 3, 4, 5];Var B = a. unshift (-2,-1); // a: [-2,-,] B: 7Note: In IE6.0, the test return value is always undefined, and in FF2.0, the test return value is 7. Therefore, the return value of this method is unreliable. You need to use splice instead of this method when returning the value.
excluding the entry at the end position NBSP; Span style= "FONT-SIZE:14PX; Color: #000000; " >ARR1 = [1,2,3,4,5]; result = Arr1.slice (2,5);//[3,4,5] result = Arr1.slice (2); [3,4,5] In the case of only one argument, the slice () method returns all items starting at the specified position of the parameter to the end of the current array;
no
8
Splice Delete or replace some items of the current array, affecting the ori
return the length of the array.Var a = [1, 2, 3, 4, 5];Var B = a. unshift (-2,-1); // a: [-2,-,] B: 7Note: In IE6.0, the test return value is always undefined, and in FF2.0, the test return value is 7. Therefore, the return value of this method is unreliable. You need to use splice instead of this method when returning the value.
Pop: Delete the last entry of the original array and return the value of the deleted element. If the array is empty, undef
Split converts the string into an array and outputs the Code:
Copy codeThe Code is as follows:
Js deletes array elements:
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.Copy codeThe Code is as foll
))
{
From = len-1;
}
Else
{
From = (from ? Math. ceil (from)
: Math. floor (from );
If (from From + = len;
Else if (from> = len)
From = len-1;
}
For (; from>-1; from --)
{
If (from in this
This [from] === elt)
Return from;
}
Return-1;
};
}
Array. prototype. insertAt = function ($ value, $ index)
{
If ($ index This. unshift ($ value );
Else if ($ index> = this. length)
This. push ($ value );
Else
This.
Summary of several methods for deleting arrays in js
This article mainly summarizes several methods for deleting arrays in js. For more information, see.
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 u
yesterday, a scene like This: there is a non-paged list of goods, there may be thousands of data (and possibly static Data) and even more, there is a delete function, we need to delete some of these items.My first reaction was that too much data could not loop through the entire array, only to get to their index, and then iterate over the index, using the Array's splice () method to delete it. And I did, but I found a fatal Bug.The reason for the bug
): splice () method:First, he and slice have only one letter difference, but the use is completely different.It can be used to delete objects.VaR A = [1, 2, 3];A = A. splice (0, 2 );Alert (a); // output 1, 2A = A. splice (1, 2 );Alert (a); // Output 2. If it is a = A. splice (0, 1); Output 1A = A.
Array---Common properties and methods summary 1, Array object constructor1 /*Array Object Constructors*/2 3 /*Combination Memory shift unshift POP push4 Add and remove5 shift Unshift from the beginning of the array to add or remove6 pop push is added or removed from the end of the array7 */8 9 //Shift: Deletes the first item of the original array and returns the value of the deleted element; returns undefined if the array is emptyTen varARR1 = [1,2,3,4,5]; One varARR2 = [1,2
Method/Step:
1 Packing:
Super 5 Type network cable marked with cat5e words should be 305 meters (1000 feet) per carton, marked with CAT5 is 5 class line, packaging is not 305.1-meter box may not be network cable. Line above the logo: regular manufacturers of the product logo on the label has length, do the project to facilitate the identification of 1-box line used how many meters, how many rice noodles left
2 with multimeter test:
GB Cable 305 me
wiring Application Analysis
In view of current network application, it is very important to design the topological structure of twisted cable for digital output correctly.
From the standard cabling Network application diagram, we can clearly see the relationship between transmission medium and network equipment and node equipment. For example, terminal equipment all choose 10MBIT/S Network card as an excuse, then the whole wiring all use CAT3 twisted pair cable can meet the design requirements
);//["Eee", "AAA", "BBB", "CCC"]
Intercept array Slice ()
Slice (intercept start position, intercept end position) Slice can have two parameters, the first parameter is required, the second parameter is optional, when there is only one parameter, the default intercept to the end of the array, and the second parameter can have positive and negative two cases, If the second argument is a negative number, the ending position of the intercept is counted from the end.1 vararr = [1,2,3,4
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.