DEV Community

Cover image for Difference between Reflect.ownKeys() and Object.keys()?
Jasmin Virdi
Jasmin Virdi

Posted on

11 3

Difference between Reflect.ownKeys() and Object.keys()?

In this post we will be comparing Reflect.ownKeys() and Object.keys() method. In first glance we might feel that they produce same result but actually they behave differently in some situation.

Let's take some examples to understand the difference between them.

Reflect.ownKeys()

This method returns an array of target objects own property which mainly is the array of all properties (enumerable or not) and symbol properties found directly upon the given object.

To understand this better let us consider this example.

reflect keys

In this example we saw that the properties and the symbols properties were printed in the result.

Object.keys()

This method only returns enumerable properties of an object.

Let's take the above example to understand this better.

object keys

As compared to the previous result we just got the objects property in the result.

The major difference is that Reflect.ownKeys() method returns symbol properties and objects properties even if it is not enumerable which is not the case with Object.keys().

Feel free to add up to this post.😊

Happy Learning! 👩🏻‍💻

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay