For example, data A, general access to each data will be
for (Var x=0;x<a.length;x++)
{
Alert (A[x])
}
The concise wording is
for (Var x in a)
{
Alert (A[x])
}
A simple notation for a new array
d=[1,2,3,3,4,3,2,2]
Or
d={1,2,3,3,4,3,2,2}
If string, use
D= "ASFWF,ASDF,W,X,,A,SFW,,X,ASFW,". Split (",")
More simple
take the beginning of the second position in string C
Some people will write C = c.substring (1,c.length)
In fact, C = c.substring (1) on the line
takes a character from the string C to the first position
Some people will write
A = c.substring (x,x+1)
or a = C.substr (x,1)
You can use a = C.charat (x) instead
To determine whether a variable A is a number, I generally use the following method, do not know if there is no simpler
if (A==parseint (A + ")) {}
if (!isnan (a)) {}
Do not send that expansion, because some of the situation considered more, to give three simplified version of the function:
<textarea id="runcode58807"><script> Array.prototype.each = function (c) {var ret = []; for (var i = 0; i < this.length i++) {Ret.push (C (this[i))); return ret; Array.prototype.any = function (c) {for (var i = 0; i < this.length. i++) {if (c (this)) return true; return false; } Array.prototype.all = function (c) {for (var i = 0; i < this.length; i++) {if (!c (this)) return false; return true; Alert ([1,2,3].each (function (x) {return x+1})); Get 2,3,4 alert ([1,-1,2].any (function (x) {return x<0})); Determines whether an element in the array is less than 0 alert ([1,2,3].all (function (x) {return x>0})); Determines whether all elements in the array are greater than 0 </script></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
<script>//This is the most stupid writing document.write ("asfasf") document.write ("ASFWFW") document.write ("asf<p>") t= "Asfas" F "+" ASFWFW "+" asf<p> "document.write (t)///above can be written in the following simplified style t=" asfasf\ asfwfw\ asf<p> "document.write ( T) </SCRIPT>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
<ptml><pead> <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "> <title> magic Wang Lijiang </title> <style> body{margin:5 0} table{border-collapse:collapse} b Ody,td{font-size:12px;cursor:default} a:link,a:visited{color: #006600; Text-decoration:none} a:hover {color: #9900FF ; Text-decoration:underline} </style></pead> <body> <script language= "JavaScript" > d=[1,213, 1,1,1,1,2,2,3,3,2,1,2,2,2,3,2,2,2,2,3,24,21,5,5,1,23,4,23,2,2,2,23,3,,3,3,5,7,7,4,4,5,543,3,3] Var a,b var t1=new Date () for (Var x=0;x<d.length;x++) {B=d[x]} var t2=new Date () for (Var x. in d) {b=d[x]} var T3=ne W Date () t= "Array small case:" if (t2-t1>t3-t2) t+= "for in" if (T2-T1==T3-T2) t+= "Same" if (T2-T1<T3-T2) t+= "for in Slow" for (x=0;x<1000;x++) {d[d.length]=x} t1=new date () for (Var x=0;x<d.length;x++) {B=d[x]} t2=new date () for (Var x. in d) {b=d[x]} t3=new Date () C=d.length for (varx=0;x<c;x++) {B=d[x]} var t4=new Date () t+= "<p> array length 10000:" if (t2-t1>t3-t2) t+= "for in Fast" if (t 2-T1==T3-T2) t+= "Same" if (T2-T1<T3-T2) t+= "for In" "t+=" <p> variable to Value: "if (T3-T2>T4-T3) t+=" for in Slow "if (t3-t2==t4- T3) t+= "Same" if (T3-T2<T4-T3) t+= "in Fast" document.write (t) </SCRIPT> </body></ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
<script > var list=new Array (); var t=wt (); for (var i=0;i<10000; i++) List.push (i); var t2=wt (); for (var i=0;i<10000; i++) X=list[i]; WT (); for (var i in list) x=list[i]; WT (); function wt () {var d=new Date (); var m=d.getmilliseconds (); document.write (D.getmilliseconds () + ""); return m; } </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]