直接上代码:
JavaScript代码:
1 var array=[{name:"张珊",sex:"男"}]; 2 console.log(array); 3 if(array[0].name){ 4 console.log('name');//返回name 5 } 6 7 if(array[0].size){ 8 console.log('size') 9 }else{ 10 console.log('no size');//返回no size 11 }
打印结果: