如何获取对象的长度?

1.我们知道,字符串(string)、数组(array)的长度可以直接用.length来获取,但对象的长度不能用.length获取,用js原生的Object.keys可以获取到,例:

var kfc = {
        ip:11233566,
        ki:6899,
        vip:"king",
        ctf:"kill",
        "home":"hello"
    };
var jgm = Object.keys(kfc);
var foo = Object.values(kfc);
console.log(jgm); //["ip", "ki", "vip", "ctf", "home"]
console.log(foo); //[11233566,6899,"king","kill","hello"]
console.log(jgm.length); // 5

你可能感兴趣的:(web前端)