js获取对象长度

//建立对象
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.length)
原文链接:,转发请注明来源!
评论已关闭。