js中有null和undefined,null是指對象不存在,undefined是指原生數據不存在
?
var h = {name:'lisi',age:28};
console.log(h.name)//對象用的是點語法,php中是name->'lisi'
下面是數組,數組用的是【】語法
1 var arr = ['a',3,'hello',true]; 2 console.log(arr); 3 //顯示結果為 4 ["a", 3, "hello", true]
它的索引不會空缺,如果你刪掉某個索引,它會立即重排,從0開始往下排
var arr = ['a',3,'hello',true]; console.log(arr[3]); //結果為true,下標從0開始
但是,對象也可以用中括號
console.log(h['name']);//結果為lisi
所以,js中對象很像php中的關聯數組,perl語言中的哈希,也叫關聯數組