Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sidebar: jsref
---

The **`find()`** method of {{jsxref("Array")}} instances returns the first element in the provided array that satisfies the provided testing function.
If no values satisfy the testing function, {{jsxref("undefined")}} is returned.
If no values satisfies the testing function, {{jsxref("undefined")}} is returned.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


- If you need the **index** of the found element in the array, use {{jsxref("Array/findIndex", "findIndex()")}}.
- If you need to find the **index of a value**, use {{jsxref("Array/indexOf", "indexOf()")}}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ browser-compat: javascript.builtins.Array.indexOf
sidebar: jsref
---

The **`indexOf()`** method of {{jsxref("Array")}} instances returns the first index at which a
given element can be found in the array, or -1 if it is not present.
The **`indexOf()`** method of {{jsxref("Array")}} instances returns the first index at which an element can be found in the array, or -1 if it is not present.

{{InteractiveExample("JavaScript Demo: Array.prototype.indexOf()")}}

Expand Down Expand Up @@ -36,10 +35,10 @@ indexOf(searchElement, fromIndex)
### Parameters

- `searchElement`
- : Element to locate in the array.
- : The element to locate in the array.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the other parameter descriptions start with "The" or "A" either, and I think it's fine either way.

- `fromIndex` {{optional_inline}}
- : Zero-based index at which to start searching, [converted to an integer](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number#integer_conversion).
- Negative index counts back from the end of the array — if `-array.length <= fromIndex < 0`, `fromIndex + array.length` is used. Note, the array is still searched from front to back in this case.
- Negative index counts back from the end of the array — if `-array.length <= fromIndex < 0`, `fromIndex + array.length` is used. Note: the array is still searched from front to back in this case.
- If `fromIndex < -array.length` or `fromIndex` is omitted, `0` is used, causing the entire array to be searched.
- If `fromIndex >= array.length`, the array is not searched and `-1` is returned.

Expand All @@ -49,7 +48,7 @@ The first index of `searchElement` in the array; `-1` if not found.

## Description

The `indexOf()` method compares `searchElement` to elements of the array using [strict equality](/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality) (the same algorithm used by the `===` operator). [`NaN`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN) values are never compared as equal, so `indexOf()` always returns `-1` when `searchElement` is `NaN`.
The `indexOf()` method compares `searchElement` to elements of the array using [strict equality](/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality) (the same algorithm used by the `===` operator). [`NaN`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN) values are never considered equal, so `indexOf()` always returns `-1` when `searchElement` is `NaN`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is an improvement


The `indexOf()` method skips empty slots in [sparse arrays](/en-US/docs/Web/JavaScript/Guide/Indexed_collections#sparse_arrays).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The `some()` method is an [iterative method](/en-US/docs/Web/JavaScript/Referenc

`callbackFn` is invoked only for array indexes which have assigned values. It is not invoked for empty slots in [sparse arrays](/en-US/docs/Web/JavaScript/Guide/Indexed_collections#sparse_arrays).

`some()` does not mutate the array on which it is called, but the function provided as `callbackFn` can. Note, however, that the length of the array is saved _before_ the first invocation of `callbackFn`. Therefore:
`some()` does not mutate the array on which it is called, but the function provided as `callbackFn` can. However, note that the length of the array is saved _before_ the first invocation of `callbackFn`. Therefore:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is an improvement in any way. We have may such cases if you search "Note, however,".


- `callbackFn` will not visit any elements added beyond the array's initial length when the call to `some()` began.
- Changes to already-visited indexes do not cause `callbackFn` to be invoked on them again.
Expand Down