JavaScript object Object.keys() method
- Previous Page isSealed()
- Next Page preventExtensions()
- Go Up One Level JavaScript Object Reference Manual
Definition and usage
Object.keys()
The method returns an array iterator object with object keys.
Object.keys()
The method does not change the original object.
Instance
Example 1
Using Object.keys() on an array:
const fruits = ["Banana", "Orange", "Apple", "Mango"]; const keys = Object.keys(fruits);
Example 2
Using Object.keys() on a string:
const fruits = "Banana"; const keys = Object.keys(fruits);
Example 3
Using Object.keys() on an object:
const person = { firstName: "Bill", lastName: "Gates", age: 19, eyeColor: "blue" }; const keys = Object.keys(person);
Syntax
Object.keys(object)
Parameter
Parameter | Description |
---|---|
object | Required. An iterable object. |
Return value
Type | Description |
---|---|
Array | An array iterator object containing object keys. |
Browser support
Object.keys()
Is an ECMAScript6 (ES6) feature.
All modern browsers support ES6 (JavaScript 2015).
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Supports | Supports | Supports | Supports | Supports |
Internet Explorer 11 (and earlier versions) does not support Object.keys()
.
Related pages
- Previous Page isSealed()
- Next Page preventExtensions()
- Go Up One Level JavaScript Object Reference Manual