计算对象的长度

转载出处:https://blog.csdn.net/xm_csdn/article/details/78431879

对象长度

[javascript]  view plain  copy
 
  1. var bookAuthors = {  
  2.     "Farmer Giles of Ham": "J.R.R. Tolkien",  
  3.     "Out of the Silent Planet": "C.S. Lewis",  
  4.     "The Place of the Lion": "Charles Williams",  
  5.     "Poetic Diction": "Owen Barfield"  
  6. };  
  7. // 获取对象的key值  
  8. var arr = Object.keys(bookAuthors);  
  9. console.log(arr);  
  10. // 获取长度  
  11. console.log(arr.length);  

数据长度

[javascript]  view plain  copy
 
    1. var arr = ["zuojj", "benjamin", "www.zuojj.com"];  
    2. //Outputs: ["0", "1", "2"]  
    3. console.log(Object.keys(arr));  
    4. //Outputs: 3  
    5. console.log(arr.length);

猜你喜欢

转载自www.cnblogs.com/wanlibingfeng/p/9186597.html