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! 👩🏻‍💻

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more