您可以使用以下计数函数:<script>function countobjkey(var1){let size=0;for(let k in var1) { size++}return(size);}var person = {fname:"John", lname:"Doe", age:25};var car = {engine:"X4", brand:"Toyota", cc:'1300', color:'black'};alert(countobjkey(person));alert(countobjkey(car));</script>