jQuery获取和计算对象(object)的长度

原文:http://www.php.cn/js-tutorial-367684.html

对象长度

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);


猜你喜欢

转载自blog.csdn.net/xm_csdn/article/details/78431879