转载出处:https://blog.csdn.net/xm_csdn/article/details/78431879
对象长度
- 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);