Example 1 — Basic Use
List the own string names on a simple object.
var car = {
brand: "Tesla",
year: 2024
};
console.log(Object.getOwnPropertyNames(car)); How It Works
- Create an object Both
brandandyearare own string properties. - List the names
Object.getOwnPropertyNames(car)returns an array of those names. - Same as keys here When every property is enumerable, the result matches
Object.keys().

