---
title: "Discussion on \"Prevent an object key from appearing in `Object.keys()` or `for..in` loop\" | Hashnode"
description: "Discussion on \"Prevent an object key from appearing in `Object.keys()` or `for..in` loop\". const obj = { name: \"Human\", age: 26, location: \"World\", role: \"Developer\" };\n\nconsole.log(Object.keys(obj)); // [ 'name', 'age', 'location', 'role' ]\n\n// Updating setting for `name` property \nObject.defineProperty(obj, \"name\", {\n  enumerable: false,..."
url: "https://hashnode.com/posts/prevent-an-object-key-from-appearing-in-objectkeys-or-forin-loop/5ff32d8d72eafd0f1c8c66af"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Prevent an object key from appearing in \`Object.keys()\` or \`for..in\` loop](https://codedrops.hashnode.dev/prevent-an-object-key-from-appearing-in-objectkeys-or-forin-loop?utm_source=hashnode&utm_medium=feed)

const obj = { name: "Human", age: 26, location: "World", role: "Developer" }; console.log(Object.keys(obj)); // \[ 'name', 'age', 'location', 'role' \] // Updating setting for \`name\` property Object.defineProperty(obj, "name", { enumerable: false,...

Jan 4, 2021 · 1 min read · codedrops.hashnode.dev  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#web-development](https://hashnode.com/tag/web-development)
-   [#codenewbies](https://hashnode.com/tag/codenewbies)
-   [#beginners](https://hashnode.com/tag/beginners)

## Written by

[Mehul Lakhanpal](https://hashnode.com/@ml318097)

@ml318097 · Bangalore, India

  
[View profile](https://hashnode.com/@ml318097)

Full-stack Developer

## Responses 1

Markdown supported · ⌘↵ to post

[Purvi Barot](https://hashnode.com/@purvi)

[Jan 19, 2021](https://hashnode.com/posts/prevent-an-object-key-from-appearing-in-objectkeys-or-forin-loop/5ff32d8d72eafd0f1c8c66af/comment/600656f2848f4c3b9a0f21a0)

The Object.keys() method returns an array of a given object's own enumerable property names, iterated in the same order that a normal loop would.

```
const object1 = {
  a: 'somestring',
  b: 42,
  c: false
};

console.log(Object.keys(object1));
// expected output: Array ["a", "b", "c"]
```

```
let unorderedData = {
  real_name: 'Millie Bobby Brown',
  character_name: 'Eleven',
  series: 'Stranger Things'
};
console.log(JSON.stringify(unorderedData));

const orderedData = {};
Object.keys(unorderedData).sort().forEach(function(key) {
  orderedData[key] = unorderedData[key];
});

console.log(JSON.stringify(orderedData));
```
