Home > Javascript > JavaScript (3)

JavaScript (3)

轉眼到了Week 10,談及更多array,貌似Week 11之後就沒有了!

Functions related to arrays:

  • arrayName.length
  • arrayName.splice(startNum,countNum);
    //從arrayName的startNum位置開始,裁掉countNum數目
  • arrayName.slice();
    //將arrayName的所有數值複製一份
  • arrayName.push(newItem);
    //將newItem加到arrayName的新位置,等同arrayName[arrayName.length]=newItem;

Associative array:

  • var myAssoc = {“key1″:”val1″,”key2″:”val2”};
    myAssoc[key] =val3;
    //JavaScript中,所有元素都是objects,而associative array是更接近object的一種array

For-in loop:

  • for ( var name in array ) {console.log(array[name]);}

JavaScript is about reference:

  • 當用x=y的時候(x和y都另有指向),實際我們只是將x導向y,一旦y改變,x的值亦將改變,而x的值改變,y的值亦會改變

Control flow:

  • 當電腦執行JavaScript時,會由左至右,由上至上運行,當遇到function時,會暫停順序運算,先處理好function
  • 由電腦計算出的結果會儲存在Stacks中,每當function運行,其結果均會儲存在Stack中
Categories: Javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: