ใช้ Object.keys() แล้วดู .length เพราะ Associative Array ใน JS เป็น Object
ตัวอย่างโค้ด
var details = new Array();
details["Name"] = "John";
details["Age"] = 21;
details["CountryName"] = "US";
details["SubjectName"] = "JavaScript";
console.log("The length==" + Object.keys(details).length);
วิธีรันโปรแกรม
ใช้คำสั่ง node fileName.js (เช่น node demo.js)
ผลลัพธ์
The length==4