Created
January 18, 2016 09:27
-
-
Save twlca/bedaf314c9e44afebdb8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 定義新的陣列 array | |
var 五都 = ["台北市", "新北市", "台中市", "台南市", "高雄市"]; | |
console.log( 五都.length ); | |
// 5 | |
// 取得陣列的元素,元素由 0 起算 | |
var 首都 = 五都[0]; | |
// "台北市" | |
var 南部第一大都市 = 五都[五都.length - 1]; | |
// "高雄市" | |
// 取得陣列中的元素 | |
五都.foreach( function( item, index, array ) { | |
console.log( item, index ); | |
}); | |
// "台北市", 0 | |
// "新北市", 1 | |
// "台中市", 2 | |
// "台南市", 3 | |
// "高雄市", 4 | |
// 加入一新元素到陣列尾端 | |
var newLength = 五都.push( "桃園市" ); | |
// ["台北市", "新北市", "台中市", "台南市", "高雄市", "桃園市"]; | |
// 由陣列尾端移除元素 | |
var 移除的元素 = 六都.pop(); | |
// ["台北市", "新北市", "台中市", "台南市", "高雄市"]; | |
// 加入一新元素到陣列頭端 | |
var 移除的元素 = 六都.shift(); | |
// ["新北市", "台中市", "台南市", "高雄市", "桃園市"]; | |
// 加入一新元素到陣列頭端 | |
var newLength = 六都.unshift( "台北市" ); | |
// ["台北市", "新北市", "台中市", "台南市", "高雄市", "桃園市"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment