CodesJava

Easy learning with example program codes

Object.getOwnPropertySymbols() JavaScript JS

The Javascript Object getOwnPropertySymbols() method retrieves an array of all own symbol key properties. It will return an empty array if no symbol property is directly associated with object.

Syntax:

Object.getOwnPropertySymbols(object) 

Parameters:
object: It represents the object whose symbol properties have to be fetched.

Return:
An array of all own symbol key properties.

Example:

<!DOCTYPE html>
<html>
<body>
<script>
const obj = {};  
x = Symbol('alpha');  
y = Symbol.for('beta');  
obj[x] = 'HELLO';  
obj[y] = 'WORLD';  
const objSymbols = Object.getOwnPropertySymbols(obj);  
document.write(objSymbols.length);    
</script>
</body>
</html>

Output:

2
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status