Reflect.ownKeys() JavaScript JS

The JavaScript Reflect.ownKeys() method gives an array whose values represent the keys of the properties of an object. It includes only the object’s direct properties.

Syntax:

Reflect.ownKeys(target)

Parameters:
target: It represents the object from which to get the own keys.

Return:
It returns an array of the target object’s own property keys.

Note: It throws TypeError if the target is not an Object.

Example 1:

<!DOCTYPE html>
<html>
<body>
<script>
const hello = {alpha: 100, beta: 200, gamma: 300};
document.write(Reflect.ownKeys(hello));
</script>
</body>
</html>

Example 2:

<!DOCTYPE html>
<html>
<body>
<script>
const object1 = {
property1: "w3schools",
property2: "jai"
};
var array1 = [];
document.write(Reflect.ownKeys(object1));
document.write("</br>");
document.write(Reflect.ownKeys(array1));
</script>
</body>
</html>