JavaScript Object.keys()
Example
Use Object.keys() on an array:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
const keys = Object.keys(fruits);
Try it Yourself »
Use Object.keys() on a string:
const fruits = "Banana";
const keys = Object.keys(fruits);
Try it Yourself »
Use Object.keys() on an object:
const person = {
firstName: "John",
lastName: "Doe",
age: 50,
eyeColor: "blue"
};
const keys = Object.keys(person);
Try it Yourself »
Definition and Usage
The Object.keys()
method returns an Array Iterator object with the keys of an object.
The Object.keys()
method does not change the original object.
Syntax
Object.keys(object)
Parameters
Parameter | Description |
object | Required. An iterable object. |
Return Value
Type | Description |
An array | An Array Iterator object containing the keys of an object. |
Browser Support
Object.keys()
is an ECMAScript6 (ES6) feature.
ES6 (JavaScript 2015) is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
Object.keys()
is not supported in Internet Explorer 11 (or earlier).