Skip to content

Object values #7484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions content/javascript/concepts/objects/terms/values/values.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
Title: '.values()'
Description: 'Returns an array containing the values of an object’s own enumerable properties.'
Subjects:
- 'Computer Science'
- 'Web Development'
Tags:
- 'JavaScript'
- 'Methods'
- 'Objects'
- 'Properties'
CatalogContent:
- 'introduction-to-javascript'
- 'paths/front-end-engineer-career-path'
---

The **`Object.values()`** method returns an array containing the values of an object's own enumerable properties. It's useful when you only need the values, not the keys.

## Syntax

```pseudo
Object.values(obj)
```

**Parameters:**

- `obj`: The object whose own enumerable property values needs to be retrieved.

**Return value:**

- An array of the object’s own enumerable property values, ordered by integer keys first (ascending), then string keys in insertion order.

## Example 1: Basic usage of `Object.values()`

In this example, `Object.values()` creates an array of property values from an object:

```js
const teamA = {
firstName: 'Liany',
animal: 'cat',
age: 30,
};

const values = Object.values(teamA);
console.log(values);
```

This example results in the following output:

```shell
["Liany", "cat", 30]
```

## Example 2: Iterating over values

In this example, `Object.values()` is used with a `for...of` loop to iterate through numeric values in an object:

```js
const scores = { teamLiany: 100, teamWife: 106, teamPrincess: 142 };

for (const value of Object.values(scores)) {
console.log(value);
}
```

This example results in the following output:

```shell
100
106
142
```

## Codebyte Example: `Object.values()` with `.filter()` method to detect booleans in a config object

In this example, `Object.values()` is combined with [`.filter()`](https://www.codecademy.com/resources/docs/javascript/arrays/filter) to extract only boolean values from an object:

```codebyte/javascript
const catObject = {
ears: true,
nose: "little",
beans: true,
wings: false,
tails: 1,
}

const booleanValues = Object.values(catObject).filter((value) => typeof value === "boolean");

console.log(booleanValues);
```