hjr-JavaScript 各種資料操作
阿新 • • 發佈:2018-12-15
js有幾種主要資料型別
- json字串: var jsonStr = “{key:value}”
- 陣列:var arry = [] 陣列 操作 arry[“xxx”] = “xxx”; 或 arry.push();
- json物件:var json = {} json物件 操作 json.xxx = “xxx”
- map物件:var map = new Map(); map.put(key,value)
幾種資料型別可以互包含
map刪除元素 for(var key in map){ delete map[key]; } map遍歷 並轉化為arry angular.forEach(mapObj,function(value,index){ var json = {}; json["key "] = index; json["name"] = value; jsonArry.push(json) }); map遍歷 並轉化為json angular.forEach(mapObj,function(value,index){ var json = {}; json.key = index; json.value= value; jsonArry.push(json) });