如何计算JavaScript数组对象?
为了计算JavaScript数组对象,我们使用Object.prototype.__proto__属性。
示例
您可以尝试运行以下代码来计算数组对象-
<html> <head> <title>JavaScript Clone Date</title> </head> <body> <script> var len = 0; var myArr = [{"你好,世界!":"Welcome!","int":10},{"Learn":"Share","int":20},{"Tutorials":"Quiz","int":30}]; myArr.forEach(function(val){ if(!val.__proto__.__proto__){ len++; } }); document.write("Total Objects: "+len); </script> </body> </html>
输出结果
Total Objects: 3