
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What is non-enumerable property in JavaScript and how can it be created?
Non-enumerable property
Objects can have properties that don't show up when iterated through the particular object using Object.keys() or for...in loop.Those type of properties are called as non-enumerable properties.
Creating a non-enumerable property
To create a non-enumerable property we have to use Object.defineProperty() method. This a special method to create non-enumerable properties in an object.
In the following example, three properties such as name, age and country were created normally and a property named "salary" was created using Object.defineProperty() method and key named enumerable was assigned with false. When the object "person" got iterated using Object.keys() the properties such as name, age and country were shown up whereas property "salary" was unable to shown up. Since salary property was unable to shown up it is called as non-enumerable property. This is the way to create non-enumerable properties.
Object.defineProperty() is also let you create read-only properties as we saw below, we are not able to modify salary value of a person object. To make the salary property enumerable assign true to the key named enumerable.
Example
<html> <body> <script> var person = { name: 'gopal' }; person.age = '21'; person['country'] = 'India'; Object.defineProperty(person, 'salary',{ value : '80,000$', enumerable: false }) document.write(Object.keys(person)); </script> </body> </html>
Outputname,age,country
- Related Articles
- What is the importance of "enumerable" attribute in defining a property in JavaScript object?
- What is reverberation? How can it be reduced?
- Can energy be destroyed? Can energy be created ?
- What is a recursive and recursively enumerable language?
- How can bubble charts be created using Matplotlib?
- What is Array Decay in C++? How can it be prevented?
- How to return an array whose elements are the enumerable property values of an object in JavaScript?
- What is SciPy in Python? Explain how it can be installed, and its applications?
- What is the potential difference? And how is it created in a battery or a cell?
- What was the name of JavaScript when it was created?
- What is the meaning of “SELECT” statement in MySQL and how can it be used?
- How many ways a String object can be created in java?
- How many types of JDialog boxes can be created in Java?
- How can grid plot in Bokeh library be created with Python?
- How can series be created using Numpy and passing index value explicitly in Python?
