programming-examples/js/Object/Retrieve all the names of object's own and inherited properties.js

16 lines
425 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
function allKeys(obj) {
if (!isObject(obj)) return [];
var keys = [];
for (var key in obj) keys.push(key);
return keys;
}
function isObject(obj)
{
var type = typeof obj;
return type === 'function' || type === 'object' && !!obj;
}
function Student(name) {
this.name = name;
}
Student.prototype.rollno = true;
console.log(allKeys(new Student("Sara")));