Recently, ESET add my domain name to the black-list of their database. You can’t open my site and been warned my site is not safe if your PC is running the ESS or EAV. Why Eset block my site?The answer is obvious. That is reason that you come here. I promise that my site is pure, no virus, no spyware, no Trojan, no pop ads. You can test my word through intalling Kaspersky or other Antivirus Software. If you want open my site and take latest escalation ID & Activation Code, close your ESET software(disable antivirus and antispyware protection function temporarily) or by proxy or virtual machinor. You can also feed the RSS source http://feed.loserblog.cn.
Home > Programm > Concerning the JavaScript several

Concerning the JavaScript several

In the JavaScript, establish 1 can use new Array and as follows three kinds of phrasings are all correct:

ArrayObj= the new Array() establish 1

ArrayObj= the new Array([size]) establish an also appointed length and the attention isn't an upper limit, is a length

arrayObj = new Array([element0[, element1[, ...[, ElementN]]]]) establish 1 and endow with a value

Wanting what to explain BE, although the second method established a several to specify length,actually all circumstances be next several to all become long, be also say that even specified length to 5, still can be saving the chemical element is rule length outside, attention:The length will immediately change at this time.
Does the new Array(5) mean that establishing a length as 5 severals still keeps establishing a chemical element to be worth to 5 severals?Establish a length is 5 severals.

Are several next marks still from one beginning from 0 beginnings?From 0 beginnings, so the upper limit of the several equals several lengths-1.

How much is several's descending a biggest value of object ?232 powers reduce again 2, namely 4294967295, about 4,000,000,000, enough meet expenses.

Under the several mark for the fraction would automatically take whole?Can't, will neglect or take place circulate hour mistake.

Do you support many Wei a several?Nonsupport!However can define each chemical element of several again for several with attain many purposes of the Wei several.

How visit several chemical elements?The usage"[]", for example several be named arr, visit the first chemical element, use arr[0].
The JavaScript several(JScript edition 2) totally has 3 attributes, 13 methods.Only length is more important in 3 attributes, but more simple, another constructor and prototype attribute are totally an object to have of and seldom use, so don't make introduction to the Array attribute, but to Array 13 method cents set introduction, easy to memory.
Pop and push:The pop move in addition to the last chemical element also returns to that chemical element value;push([item1 [item2 [. . . [itemN ]]]])Add 1 or many new chemical elements to several codas, and return to several new lengths, if what to add is a several of each chemical element conjunction which then uses first to stir number and will should be several to get up to add again.
Shift and unshift:Difference to should at the pop and the push, just this is at several of the beginning position carry on.Noticed to be to move from the beginning position in addition to or add a chemical element, meeting the chemical element in the several ago move or behind move.
Slice and splice:The slice(start, ) returns to a several by the form of several of a part, the attention doesn't include end to in response to of chemical element, if abridge end will after making duplicate start of all chemical elements;splice(start, deleteCount, [item1[, item2[, . . . [,itemN]]]])移除数组一个或多个元素,如果必要,在所移除元素的位置上插入新元素,数组形式返回所移除的元素,如果插入的是数组,则只插入数组的第一个元素。
Reverse and sort:The reverse() turns over a chemical element(the most ex- row till the last, end of line up to arrive the ex-est), and returns to several addresses;Sort() logarithms set row preface and return to several addresses.
Concat and join:The concat links many piece set(can be a string) as 1;The join(separator) returns to a string, this string link each chemical element value of several together and in the center partitions with the separator.
ToLocaleString, toString, valueOf:Can see make the special method of using which is a join, seldom use.

Delete several chemical elements

Once saw an article, the step which says the deletion several in some one chemical element should be so:
1, delete
2, the chemical element moved ago
3, heavy establish several lengths

In fact using several method splices can one-step completion.
arrayObject.splice(start, deleteCount, [item1[, item2[, . . . [,itemN]]]])

The start wants to delete of beginning position

The deleteCount wants to delete of piece

item1, item2, . . ., If the itemN is appointed this value, can at delete of the position insert a chemical element.If what to insert is a several, take the first chemical element just then.



Copy a several

Sometimes need to endow with the value of 1 to the another, usage as follows code:

<script type="text/javascript" language="javascript">
<!–
var oArr = new Array("a", "b", "c");
var dArr = oArr;
dArr[0] = "A";
document.write(oArr[0]);
//–>
</script>

But we discover while modifying the dArr several value, the oArr several values also changed, so say above-mentioned not is copy several, but make two Array objects point to the same of address.

Someone says that a chemical element ground of a chemical element endows with a value, in fact have a better method, usage concat method, as follows:
<script type="text/javascript" language="javascript">
<!–
var oArr = new Array("a", "b", "c");
var dArr = new Array;
dArr = oArr.concat();
dArr[0] = "A";

document.write(dArr[2]); //Show c
document.write(oArr[0]); //Show a
document.write(dArr[0]); //Show A
//–>
</script>

The concat(notice it to write a method) constitutes 1 or many pieces, and return to a new several, the concat parameter piece is unlimited.Moreover slice is also can.

Know the length attribute of several objects of the JavaScript

Several objects only have an attribute, this attribute is a length, it means several lengths, namely among them the piece of chemical element.Because the index of several always from 0 beginnings, so the top and bottom of 1 limit respectively BE:0 with length-1.Different from most other languageses BE, the length attribute of the JavaScript several is variable and this needs a special attention.When the length attribute is establish larger, the appearance of the whole piece set will not take place variety in fact, only is a length attribute to become big;When the length attribute is establish ratio originally hour, at first several then in index big in or equal a be worth of length chemical element to be throw all to lose.The underneath is the example which plays to show the change length attribute:

var arr=[12,23,5,3,25,98,76,54,56,76];
//Defined a several which includes 10 numerals
alert(arr.length); //Show several lengths 10
arr.length=12; //Enlarge several lengths
alert(arr.length); //Show that several lengths have already change into 12

alert(arr[8]); //Show the 9th value of chemical element, is 56
arr.length=5; //Reduce the length of several to 5, the index equal or more than 5 chemical elements be throw
alert(arr[8]); //Show that the 9th chemical element has already changed into "undefined"
arr.length=10; //Recover few senior clerks' degree to 10
alert(arr[8]); //Although the length is recovered to 10,the 9th chemical element can't take back, the manifestation"undefined"
From the code of top we can know of see the property of length attribute.But length object not only can with the constitution of show type, it also is probably modify by the concealed type.Can use 1 in the JavaScript haven't declared of change to measure, same, can also use an undefined and several chemical elements(point index to exceed or equal a length chemical element), at this time, the value of length attribute will be establish to add for the be worth of chemical element index use 1.For example the code of underneath:


var arr=[12,23,5,3,25,98,76,54,56,76];
alert
(arr.length);
arr[15]=34;
alert(arr.length);

Similarly and first defined a several which includes 10 numerals in the code, pass the alert language sentence can see its length to 10.Later on used index is 15 chemical elements, endow with it to be worth to 15, namely arr[15]=34, at this time again output several lengths with the alert language sentence, what to get is 16.Anyway, for make it a rule to a strong type plait the development personnel of the distance to say, this be a very surprising characteristic.In fact, the Array() form of the usage new establish of several, it beginning start length be is 0, is exactly as to it's medium the operation of undecided righteousness chemical element, just make several length occurrence change.

From top of the introduction can see, the length attribute is a such magic and make use of it can the convenient increment perhaps reduces several capacity.Therefore contribute to in the process of develop to thorough understanding of the length attribute in use flexibly.


Categories: Programm Tags:
  1. No comments yet.
  1. No trackbacks yet.
  • Partner links