function propertiesCount() {
let instructor = {
course: "React fundamentals",
duration: 5,
field: "frontend development"
};
console.log(Object.keys(instructor).length);
// console.log(propertiesCount(instructor)); this function is recursive
}
console.log(propertiesCount(instructor));
this console function is recursive and may cause a
maximum stack
error. Removing it will ensure smooth operation. Use return statement to retrieve the property count.
try this :
function propertiesCount(obj){
return Object.keys(obj).length;
}
var propertyLength = propertiesCount({course: "React fundamentals", duration: 5, field: "frontend development"});
// or
//let instructor = {
// course: "React fundamentals",
// duration: 5,
// field: "frontend development"
// };
// var propertyLength = propertiesCount(instructor);
// Or in ES6
// const propertiesCount = obj => Object.keys(obj).length;
console.log(propertyLength);