This could be a simple solution but I can't figure out if I can use this method or not. This question is asked before in different ways but I am looking through object methods not functions so bear with me please.
Is this possible to access objects properties and return them as an array through Object.getOwnPropertyNames(object)?
For example , this method working fine with below variable without array.
var y = {
firstName: "John",
lastName: "Doe",
eyeColor: "Black",
age: 50
};
console.log(
Object.getOwnPropertyNames(y)
);
Returns
(4) ["firstName", "lastName", "eyeColor", "age"]
can we use same method to access object properties inside array ?
var x = [{
firstName: "John",
lastName: "Doe",
eyeColor: "Black",
age: 50
}, {
firstName: "Marry",
lastName: "Smith",
eyeColor: "Brown",
age: 45
}];