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 »

Description

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 arrayAn 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 since June 2017:

Chrome 51 Edge 15 Firefox 54 Safari 10 Opera 38
May 2016 Apr 2017 Jun 2017 Sep 2016 Jun 2016

Object.keys() is not supported in Internet Explorer.


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.