Tuesday, 23 June 2015

javascript basic again -- array


---------
you can put any type of things into an array:

var beaver = ["furry,","chewy", function (){alert('xxxx')}];

---------

you can get set a new item with very large index:

beaver[100000000] = "tail";

now it has 4 items,

but don't do: alert(beaver) it will do tostring() which will connect 10000000's empty string together which will crash your pc.

---------


array with string keys:

beaver["zzz"]  = function (){
alert("xxx");
}

beaver.zzz();    // good call
beaver["zzz"]();  //good call
var aaa = "zzz";
beaver[aaa](); // good call



----------

var  beaver = {
    "aa" : "xxx",
    "bb" : function(){
       alert("bbbb");
   }
}

beaver["bb"]();


This also good: (without quotes:)
var  beaver = {
    aa : "xxx",
    bb : function(){
       alert("bbbb");
   }
}

It looks like json, but it is array (that is why all properties are divided by "," ), everything in javascript is an array!!!!

------

function is also is an array:

var aa = function(){

}

aa["a"] = "xxa";
aa.b = "xxb";





-------








No comments:

Post a comment