Array及JSON的操作
Array的操作
var list = [1,"2", [1,2,3]];Array裡的單一元素操作, 其取出copy到另一變數時遵照一般的規則
var array = [{name:"apple"}, "map", "mop"];
var secondElement = array[1]; //copy of value type
secondElement = "abc";
console.log(array); // [{name:"apple"}, "map", "mop"]; same
var firstElement = array[1]; //copy of reference type
first.name = "abc";
console.log(array); // [{name:"abc"}, "map", "mop"]; change移除第一個元素以及最後一個元素
// remove the fist one, using shift
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift(); //the length becomes 3
// remove the final one, using pop
fruits.pop(); //the length becomes 2Array的copy (array本身是reference type)
Array的deep copy/clone/duplicate (copy each element)
Array的 For-Loop
遞迴(Recursion)
Array的high order function操作map, filter, reduce
JSON的注意事項及常見處理
常見case - Loop Array 或 JSON/Map/Dictionary 時要小心的事情
Last updated