Skip to content
Merged
Show file tree
Hide file tree
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
57 changes: 57 additions & 0 deletions files/en-us/web/api/cssnumericarray/entries/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: "CSSNumericArray: entries() method"
short-title: entries()
slug: Web/API/CSSNumericArray/entries
page-type: web-api-instance-method
browser-compat: api.CSSNumericArray.entries
---

{{APIRef("CSS Typed Object Model API")}} {{AvailableInWorkers}}

The **`entries()`** method of the {{domxref("CSSNumericArray")}} interface returns a new _array iterator_ that yields `[index, value]` pairs for each item in the object.

## Syntax

```js-nolint
entries()
```

### Parameters

None.

### Return value

A new [iterable iterator](/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).

## Examples

### Iterating over index/value pairs

```js
const sum = new CSSMathSum(CSS.px(10), CSS.em(5), CSS.percent(50));

for (const [index, value] of sum.values.entries()) {
console.log(index, value.toString());
}
// 0 "10px"
// 1 "5em"
// 2 "50%"
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("CSSNumericArray.forEach()")}}
- {{domxref("CSSNumericArray.keys()")}}
- {{domxref("CSSNumericArray.length")}}
- {{domxref("CSSNumericArray.values()")}}
- [Using the CSS Typed OM](/en-US/docs/Web/API/CSS_Typed_OM_API/Guide)
- [CSS Typed Object Model API](/en-US/docs/Web/API/CSS_Typed_OM_API)
67 changes: 67 additions & 0 deletions files/en-us/web/api/cssnumericarray/foreach/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: "CSSNumericArray: forEach() method"
short-title: forEach()
slug: Web/API/CSSNumericArray/forEach
page-type: web-api-instance-method
browser-compat: api.CSSNumericArray.forEach
---

{{APIRef("CSS Typed Object Model API")}} {{AvailableInWorkers}}

The **`forEach()`** method of the {{domxref("CSSNumericArray")}} interface executes a provided function once for each item in the object.

## Syntax

```js-nolint
forEach(callbackFn)
forEach(callbackFn, thisArg)
```

### Parameters

- `callbackFn`
- : The function to execute for each element, taking three arguments:
- `currentValue`
- : The item being processed.
- `index` {{optional_inline}}
- : The index of the current element being processed.
- `array` {{optional_inline}}
- : The `CSSNumericArray` that `forEach()` is being called on.
- `thisArg` {{optional_inline}}
- : Value to use as `this` when executing `callbackFn`.

### Return value

None ({{jsxref("undefined")}}).

## Examples

### Iterating with forEach()

```js
const sum = new CSSMathSum(CSS.px(10), CSS.em(5), CSS.percent(50));

sum.values.forEach((value, index) => {
console.log(index, value.toString());
});
// 0 "10px"
// 1 "5em"
// 2 "50%"
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("CSSNumericArray.entries()")}}
- {{domxref("CSSNumericArray.keys()")}}
- {{domxref("CSSNumericArray.length")}}
- {{domxref("CSSNumericArray.values()")}}
- [Using the CSS Typed OM](/en-US/docs/Web/API/CSS_Typed_OM_API/Guide)
- [CSS Typed Object Model API](/en-US/docs/Web/API/CSS_Typed_OM_API)
49 changes: 46 additions & 3 deletions files/en-us/web/api/cssnumericarray/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,49 @@ browser-compat: api.CSSNumericArray

{{APIRef("CSS Typed Object Model API")}} {{AvailableInWorkers}}

The **`CSSNumericArray`** interface of the [CSS Typed Object Model API](/en-US/docs/Web/API/CSS_Object_Model) contains a list of {{domxref("CSSNumericValue")}} objects.
The **`CSSNumericArray`** interface of the [CSS Typed Object Model API](/en-US/docs/Web/API/CSS_Object_Model) represents an iterable of {{domxref("CSSNumericValue")}}-based objects.

An object of this type is used to represent the operands of a mathematical operation in the `values` property of {{domxref("CSSMathSum")}}, {{domxref("CSSMathProduct")}}, {{domxref("CSSMathMin")}}, and {{domxref("CSSMathMax")}}.

The items can be accessed by index (`array[0]`), and as an iterable it can be used with a {{jsxref("Statements/for...of", "for...of")}} loop or the spread syntax.

## Instance properties

- {{domxref("CSSNumericArray.length")}} {{ReadOnlyInline}}
- : Returns how many {{domxref("CSSNumericValue")}} objects are contained within the `CSSNumericArray`.
- : Returns the number of items in the object.

## Instance methods

- {{domxref("CSSNumericArray.entries()")}}
- : Returns a new _array iterator_ that yields `[index, value]` pairs for each item in the object.
- {{domxref("CSSNumericArray.forEach()")}}
- : Executes a provided function once for each item in the object.
- {{domxref("CSSNumericArray.keys()")}}
- : Returns a new _array iterator_ that yields the index of each item in the object.
- {{domxref("CSSNumericArray.values()")}}
- : Returns a new _array iterator_ that yields each item in the object.

## Examples

To do.
### Reading the terms of a `CSSMathSum`

The `values` property of a {{domxref("CSSMathSum")}} is a `CSSNumericArray` containing the terms of the sum.
This example creates a `CSSMathSum`, then reads its `values` via `length`, indexed access, and iteration.

```js
const sum = new CSSMathSum(CSS.px(10), CSS.em(5), CSS.percent(50));
const values = sum.values;

console.log(values.length); // 3
console.log(values[0]); // CSSUnitValue {value: 10, unit: "px"}

for (const value of values) {
console.log(value.toString());
}
// "10px"
// "5em"
// "50%"
```

## Specifications

Expand All @@ -25,3 +58,13 @@ To do.
## Browser compatibility

{{Compat}}

## See also

- {{domxref("CSSMathSum")}}
- {{domxref("CSSMathProduct")}}
- {{domxref("CSSMathMin")}}
- {{domxref("CSSMathMax")}}
- {{domxref("CSSNumericValue")}}
- [Using the CSS Typed OM](/en-US/docs/Web/API/CSS_Typed_OM_API/Guide)
- [CSS Typed Object Model API](/en-US/docs/Web/API/CSS_Typed_OM_API)
57 changes: 57 additions & 0 deletions files/en-us/web/api/cssnumericarray/keys/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: "CSSNumericArray: keys() method"
short-title: keys()
slug: Web/API/CSSNumericArray/keys
page-type: web-api-instance-method
browser-compat: api.CSSNumericArray.keys
---

{{APIRef("CSS Typed Object Model API")}} {{AvailableInWorkers}}

The **`keys()`** method of the {{domxref("CSSNumericArray")}} interface returns a new _array iterator_ that yields the index of each item in the object.

## Syntax

```js-nolint
keys()
```

### Parameters

None.

### Return value

A new [iterable iterator](/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).

## Examples

### Iterating over indexes

```js
const sum = new CSSMathSum(CSS.px(10), CSS.em(5), CSS.percent(50));

for (const index of sum.values.keys()) {
console.log(index);
}
// 0
// 1
// 2
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("CSSNumericArray.entries()")}}
- {{domxref("CSSNumericArray.forEach()")}}
- {{domxref("CSSNumericArray.length")}}
- {{domxref("CSSNumericArray.values()")}}
- [Using the CSS Typed OM](/en-US/docs/Web/API/CSS_Typed_OM_API/Guide)
- [CSS Typed Object Model API](/en-US/docs/Web/API/CSS_Typed_OM_API)
23 changes: 20 additions & 3 deletions files/en-us/web/api/cssnumericarray/length/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ browser-compat: api.CSSNumericArray.length

{{APIRef("CSS Typed Object Model API")}} {{AvailableInWorkers}}

The **`length`** read-only property of the {{domxref("CSSNumericArray")}} interface returns the number of {{domxref("CSSNumericValue")}} objects in the list.
The **`length`** read-only property of the {{domxref("CSSNumericArray")}} interface returns the number of items in the object.

## Value

An integer representing the number of {{domxref("CSSNumericValue")}} objects in the list.
An integer.

## Examples

To Do
### Basic usage

In this example, we read the `length` of the {{domxref("CSSNumericArray")}} returned by the `values` property of a {{domxref("CSSMathSum")}}:

```js
const sum = new CSSMathSum(CSS.px(10), CSS.em(5), CSS.percent(50));

console.log(sum.values.length); // 3
```

## Specifications

Expand All @@ -25,3 +33,12 @@ To Do
## Browser compatibility

{{Compat}}

## See also

- {{domxref("CSSNumericArray.entries()")}}
- {{domxref("CSSNumericArray.forEach()")}}
- {{domxref("CSSNumericArray.keys()")}}
- {{domxref("CSSNumericArray.values()")}}
- [Using the CSS Typed OM](/en-US/docs/Web/API/CSS_Typed_OM_API/Guide)
- [CSS Typed Object Model API](/en-US/docs/Web/API/CSS_Typed_OM_API)
57 changes: 57 additions & 0 deletions files/en-us/web/api/cssnumericarray/values/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: "CSSNumericArray: values() method"
short-title: values()
slug: Web/API/CSSNumericArray/values
page-type: web-api-instance-method
browser-compat: api.CSSNumericArray.values
---

{{APIRef("CSS Typed Object Model API")}} {{AvailableInWorkers}}

The **`values()`** method of the {{domxref("CSSNumericArray")}} interface returns a new _array iterator_ that yields each item in the object.

## Syntax

```js-nolint
values()
```

### Parameters

None.

### Return value

A new [iterable iterator](/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).

## Examples

### Iterating over values

```js
const sum = new CSSMathSum(CSS.px(10), CSS.em(5), CSS.percent(50));

for (const value of sum.values.values()) {
console.log(value.toString());
}
// "10px"
// "5em"
// "50%"
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("CSSNumericArray.entries()")}}
- {{domxref("CSSNumericArray.forEach()")}}
- {{domxref("CSSNumericArray.keys()")}}
- {{domxref("CSSNumericArray.length")}}
- [Using the CSS Typed OM](/en-US/docs/Web/API/CSS_Typed_OM_API/Guide)
- [CSS Typed Object Model API](/en-US/docs/Web/API/CSS_Typed_OM_API)
Loading