jQuery如何获取和计算对象的长度

如题所述

//对象获取
var bookAuthors = {  
    "Farmer Giles of Ham": "J.R.R. Tolkien",  
    "Out of the Silent Planet": "C.S. Lewis",  
    "The Place of the Lion": "Charles Williams",  
    "Poetic Diction": "Owen Barfield"  
};  
// 获取对象的key值  
var arr = Object.keys(bookAuthors);  
console.log(arr);  
// 获取长度  
console.log(arr.length);  

//数据长度
var arr = ["zuojj", "benjamin", "www.zuojj.com"];  
//Outputs: ["0", "1", "2"]  
console.log(Object.keys(arr));  
//Outputs: 3  
console.log(arr.length);

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-05-30
var content = $(‘div’).width();
//只是获取content宽度
var contentWithPadding = $('div').innerWidth();
//获取content+padding的宽度
var withoutMargin = $(‘div’).outerWidth();
//获取content+padding+border的宽度
var full = $('div').outerWidth(true);
//获取content+padding+border+margin的宽度