Reflect.ownKeys() JavaScript JS

The JavaScript Reflect.ownKeys() method gives an array whose values represents the keys of the properties of an object. It includes only 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 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>

Output:

alpha,beta,gamma

Example 2:

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

Output:

property1,property2
length
Please Share