recursal/MDN huggingface dataset:
Array.prototype[@@unscopables]
==============================

The **`@@unscopables`** data property of `Array.prototype` is shared by all `Array` instances. It contains property names that were not included in the ECMAScript standard prior to the ES2015 version and that are ignored for `with` statement-binding purposes.

Value
-----

A `null`-prototype object with property names given below and their values set to `true`.

| Property attributes of `Array.prototype[@@unscopables]` |
| --- |
| Writable | no |
| Enumerable | no |
| Configurable | yes |

Description
-----------

The default `Array` properties that are ignored for `with` statement-binding purposes are:

* `at()`
* `copyWithin()`
* `entries()`
* `fill()`
* `find()`
* `findIndex()`
* `findLast()`
* `findLastIndex()`
* `flat()`
* `flatMap()`
* `includes()`
* `keys()`
* `toReversed()`
* `toSorted()`
* `toSpliced()`
* `values()`

`Array.prototype[@@unscopables]` is an empty object only containing all the above property names with the value `true`. Its prototype is `null`, so `Object.prototype` properties like `toString` won't accidentally be made unscopable, and a `toString()` within the `with` statement will continue to be called on the array.

See `Symbol.unscopables` for how to set unscopable properties for your own objects.

Examples
--------

Imagine the `keys.push('something')` call below is in code that was written prior to ECMAScript 2015.


```js
var keys = [];

with (Array.prototype) {
  keys.push("something");
}
```


When ECMAScript 2015 introduced the `Array.prototype.keys()` method, if the `@@unscopables` data property had not also been introduced, that `keys.push('something')` call would break — because the JavaScript runtime would have interpreted `keys` as being the `Array.prototype.keys()` method, rather than the `keys` array defined in the example code.

So the `@@unscopables` data property for `Array.prototype` causes the `Array` properties introduced in ECMAScript 2015 to be ignored for `with` statement-binding purposes — allowing code that was written prior to ECMAScript 2015 to continue working as expected, rather than breaking.

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-array.prototype-@@unscopables |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Array.prototype[@@unscopables]` in `core-js`
* Indexed collections guide
* `Array`
* `with`
* `Symbol.unscopables`
Array.prototype.keys()
======================

The **`keys()`** method of `Array` instances returns a new *array iterator* object that contains the keys for each index in the array.

Try it
------

Syntax
------


```js
keys()
```

### Parameters

None.

### Return value

A new iterable iterator object.

Description
-----------

When used on sparse arrays, the `keys()` method iterates empty slots as if they have the value `undefined`.

The `keys()` method is generic. It only expects the `this` value to have a `length` property and integer-keyed properties.

Examples
--------

### Using keys() on sparse arrays

Unlike `Object.keys()`, which only includes keys that actually exist in the array, the `keys()` iterator doesn't ignore holes representing missing properties.


```js
const arr = ["a", , "c"];
const sparseKeys = Object.keys(arr);
const denseKeys = [...arr.keys()];
console.log(sparseKeys); // ['0', '2']
console.log(denseKeys); // [0, 1, 2]
```

### Calling keys() on non-array objects

The `keys()` method reads the `length` property of `this` and then yields all integer indices between 0 and `length - 1`. No index access actually happens.


```js
const arrayLike = {
  length: 3,
};
for (const entry of Array.prototype.keys.call(arrayLike)) {
  console.log(entry);
}
// 0
// 1
// 2
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-array.prototype.keys |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Array.prototype.keys` in `core-js`
* Indexed collections guide
* `Array`
* `Array.prototype.entries()`
* `Array.prototype.values()`
* `Array.prototype[@@iterator]()`
* `TypedArray.prototype.keys()`
* Iteration protocols
Array.prototype[@@iterator]()
=============================

The **`[@@iterator]()`** method of `Array` instances implements the iterable protocol and allows arrays to be consumed by most syntaxes expecting iterables, such as the spread syntax and `for...of` loops. It returns an array iterator object that yields the value of each index in the array.

The initial value of this property is the same function object as the initial value of the `Array.prototype.values` property.

Try it
------

Syntax
------


```js
array[Symbol.iterator]()
```

### Parameters

None.

### Return value

The same return value as `Array.prototype.values()`: a new iterable iterator object that yields the value of each index in the array.

Examples
--------

### Iteration using for...of loop

Note that you seldom need to call this method directly. The existence of the `@@iterator` method makes arrays iterable, and iterating syntaxes like the `for...of` loop automatically call this method to obtain the iterator to loop over.

#### HTML


```html
<ul id="letterResult"></ul>
```


#### JavaScript


```js
const arr = ["a", "b", "c"];
const letterResult = document.getElementById("letterResult");
for (const letter of arr) {
  const li = document.createElement("li");
  li.textContent = letter;
  letterResult.appendChild(li);
}
```


#### Result

### Manually hand-rolling the iterator

You may still manually call the `next()` method of the returned iterator object to achieve maximum control over the iteration process.


```js
const arr = ["a", "b", "c", "d", "e"];
const arrIter = arr[Symbol.iterator]();
console.log(arrIter.next().value); // a
console.log(arrIter.next().value); // b
console.log(arrIter.next().value); // c
console.log(arrIter.next().value); // d
console.log(arrIter.next().value); // e
```

### Handling strings and string arrays with the same function

Because both strings and arrays implement the iterable protocol, a generic function can be designed to handle both inputs in the same fashion. This is better than calling `Array.prototype.values()` directly, which requires the input to be an array, or at least an object with such a method.


```js
function logIterable(it) {
  if (typeof it[Symbol.iterator] !== "function") {
    console.log(it, "is not iterable.");
    return;
  }
  for (const letter of it) {
    console.log(letter);
  }
}

// Array
logIterable(["a", "b", "c"]);
// a
// b
// c

// String
logIterable("abc");
// a
// b
// c

// Number
logIterable(123);
// 123 is not iterable.
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-array.prototype-@@iterator |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Array.prototype[@@iterator]` in `core-js`
* Indexed collections guide
* `Array`
* `Array.prototype.keys()`
* `Array.prototype.entries()`
* `Array.prototype.values()`
* `TypedArray.prototype[@@iterator]()`
* `String.prototype[@@iterator]()`
* `Symbol.iterator`
* Iteration protocols
Array() constructor
===================

The **`Array()`** constructor creates `Array` objects.

Syntax
------


```js
new Array()
new Array(element1)
new Array(element1, element2)
new Array(element1, element2, /\* …, \*/ elementN)
new Array(arrayLength)

Array()
Array(element1)
Array(element1, element2)
Array(element1, element2, /\* …, \*/ elementN)
Array(arrayLength)
```


**Note:** `Array()` can be called with or without `new`. Both create a new `Array` instance.

### Parameters

`element1`, …, `elementN`

 A JavaScript array is initialized with the given elements, except in the case where
 a single argument is passed to the `Array` constructor and that argument is
 a number (see the `arrayLength` parameter below). Note that this special case only
 applies to JavaScript arrays created with the `Array` constructor, not
 array literals created with the square bracket syntax.


`arrayLength`

 If the only argument passed to the `Array` constructor is an integer
 between 0 and 232 - 1 (inclusive), this returns a new JavaScript array with
 its `length` property set to that number (**Note:** this
 implies an array of `arrayLength` empty slots, not slots with actual
 `undefined` values — see sparse arrays).


### Exceptions

`RangeError`

Thrown if there's only one argument (`arrayLength`) that is a number, but its value is not an integer or not between 0 and 232 - 1 (inclusive).

Examples
--------

### Array literal notation

 Arrays can be created using the literal
 notation:


```js
const fruits = ["Apple", "Banana"];

console.log(fruits.length); // 2
console.log(fruits[0]); // "Apple"
```

### Array constructor with a single parameter

 Arrays can be created using a constructor with a single number parameter. An array is created with
 its `length` property set to that number, and the array elements are empty
 slots.


```js
const arrayEmpty = new Array(2);

console.log(arrayEmpty.length); // 2
console.log(arrayEmpty[0]); // undefined; actually, it is an empty slot
console.log(0 in arrayEmpty); // false
console.log(1 in arrayEmpty); // false
```



```js
const arrayOfOne = new Array("2"); // Not the number 2 but the string "2"

console.log(arrayOfOne.length); // 1
console.log(arrayOfOne[0]); // "2"
```

### Array constructor with multiple parameters

 If more than one argument is passed to the constructor, a new `Array` with
 the given elements is created.


```js
const fruits = new Array("Apple", "Banana");

console.log(fruits.length); // 2
console.log(fruits[0]); // "Apple"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-array-constructor |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Indexed collections guide
* `Array`
Array.of()
==========

 The **`Array.of()`** static method creates a new `Array`
 instance from a variable number of arguments, regardless of number or type of the
 arguments.

Try it
------

Syntax
------


```js
Array.of()
Array.of(element1)
Array.of(element1, element2)
Array.of(element1, element2, /\* …, \*/ elementN)
```

### Parameters

`element1`, …, `elementN`

Elements used to create the array.

### Return value

A new `Array` instance.

Description
-----------

The difference between `Array.of()` and the `Array()` constructor is in the handling of single arguments: `Array.of(7)` creates an array with a single element, `7`, whereas `Array(7)` creates an empty array with a `length` property of `7`. (That implies an array of 7 empty slots, not slots with actual `undefined` values.)


```js
Array.of(7); // [7]
Array(7); // array of 7 empty slots

Array.of(1, 2, 3); // [1, 2, 3]
Array(1, 2, 3); // [1, 2, 3]
```


The `Array.of()` method is a generic factory method. For example, if a subclass of `Array` inherits the `of()` method, the inherited `of()` method will return new instances of the subclass instead of `Array` instances. In fact, the `this` value can be any constructor function that accepts a single argument representing the length of the new array, and the constructor will be called with the number of arguments passed to `of()`. The final `length` will be set again when all elements are assigned. If the `this` value is not a constructor function, the plain `Array` constructor is used instead.

Examples
--------

### Using Array.of()


```js
Array.of(1); // [1]
Array.of(1, 2, 3); // [1, 2, 3]
Array.of(undefined); // [undefined]
```

### Calling of() on non-array constructors

The `of()` method can be called on any constructor function that accepts a single argument representing the length of the new array.


```js
function NotArray(len) {
  console.log("NotArray called with length", len);
}

console.log(Array.of.call(NotArray, 1, 2, 3));
// NotArray called with length 3
// NotArray { '0': 1, '1': 2, '2': 3, length: 3 }

console.log(Array.of.call(Object)); // [Number: 0] { length: 0 }
```


When the `this` value is not a constructor, a plain `Array` object is returned.


```js
console.log(Array.of.call({}, 1)); // [ 1 ]
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-array.of |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Array.of` in `core-js`
* Indexed collections guide
* `Array`
* `Array()`
* `Array.from()`
* `TypedArray.of()`
RangeError() constructor
========================

The **`RangeError()`** constructor creates `RangeError` objects.

Syntax
------


```js
new RangeError()
new RangeError(message)
new RangeError(message, options)
new RangeError(message, fileName)
new RangeError(message, fileName, lineNumber)

RangeError()
RangeError(message)
RangeError(message, options)
RangeError(message, fileName)
RangeError(message, fileName, lineNumber)
```


**Note:** `RangeError()` can be called with or without `new`. Both create a new `RangeError` instance.

### Parameters

`message` Optional

Human-readable description of the error.

`options` Optional

An object that has the following properties:

`cause` Optional

 A property indicating the specific cause of the error.
 When catching and re-throwing an error with a more-specific or useful error message, this property can be used to pass the original error.



`fileName` Optional 
Non-standard

The name of the file containing the code that caused the exception

`lineNumber` Optional 
Non-standard

The line number of the code that caused the exception

Examples
--------

### Using RangeError (for numeric values)


```js
function check(n) {
  if (!(n >= -500 && n <= 500)) {
    throw new RangeError("The argument must be between -500 and 500.");
  }
}

try {
  check(2000);
} catch (error) {
  if (error instanceof RangeError) {
    // Handle the error
  }
}
```

### Using RangeError (for non-numeric values)


```js
function check(value) {
  if (!["apple", "banana", "carrot"].includes(value)) {
    throw new RangeError(
      'The argument must be an "apple", "banana", or "carrot".',
    );
  }
}

try {
  check("cabbage");
} catch (error) {
  if (error instanceof RangeError) {
    // Handle the error
  }
}
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-nativeerror-constructors |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Error`
* `Array`
* `Number.prototype.toExponential()`
* `Number.prototype.toFixed()`
* `Number.prototype.toPrecision()`
* `String.prototype.normalize()`
Generator.prototype.next()
==========================

 The **`next()`** method of `Generator` instances returns an
 object with two properties `done` and `value`. You can also
 provide a parameter to the `next` method to send a value to the
 generator.

Syntax
------


```js
next()
next(value)
```

### Parameters

`value` Optional

The value to send to the generator.

 The value will be assigned as a result of a `yield` expression. For
 example, in `variable = yield expression`, the value
 passed to the `.next()` function will be assigned to
 `variable`.


### Return value

An `Object` with two properties:

`done`

A boolean value:

* `true` if the generator is past the end of its control flow. In this case `value` specifies the *return value* of the generator (which may be undefined).
* `false` if the generator is able to produce more values.

`value`

Any JavaScript value yielded or returned by the generator.

Examples
--------

### Using next()

 The following example shows a simple generator and the object that the
 `next` method returns:


```js
function\* gen() {
  yield 1;
  yield 2;
  yield 3;
}

const g = gen(); // Generator { }
g.next(); // { value: 1, done: false }
g.next(); // { value: 2, done: false }
g.next(); // { value: 3, done: false }
g.next(); // { value: undefined, done: true }
```

### Using next() with a list

In this example, `getPage` takes a list and "paginates" it into chunks of size `pageSize`. Each call to `next` will yield one such chunk.


```js
function\* getPage(list, pageSize = 1) {
  for (let index = 0; index < list.length; index += pageSize) {
    yield list.slice(index, index + pageSize);
  }
}

const list = [1, 2, 3, 4, 5, 6, 7, 8];
const page = getPage(list, 3); // Generator { }

page.next(); // { value: [1, 2, 3], done: false }
page.next(); // { value: [4, 5, 6], done: false }
page.next(); // { value: [7, 8], done: false }
page.next(); // { value: undefined, done: true }
```

### Sending values to the generator

In this example, `next` is called with a value.

**Note:** The first call does not log anything, because the generator was not yielding anything initially.


```js
function\* gen() {
  while (true) {
    const value = yield;
    console.log(value);
  }
}

const g = gen();
g.next(1); // Returns { value: undefined, done: false }
// No log at this step: the first value sent through `next` is lost
g.next(2); // Returns { value: undefined, done: false }
// Logs 2
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-generator.prototype.next |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `function*`
* Iterators and generators guide
Generator.prototype.throw()
===========================

The **`throw()`** method of `Generator` instances acts as if a `throw` statement is inserted in the generator's body at the current suspended position, which informs the generator of an error condition and allows it to handle the error, or perform cleanup and close itself.

Syntax
------


```js
generatorInstance.throw(exception)
```

### Parameters

`exception`

The exception to throw. For debugging purposes, it is useful to make it an `instanceof` `Error`.

### Return value

If the thrown exception is caught by a `try...catch` and the generator resumes to yield more values, it will return an `Object` with two properties:

`done`

A boolean value:

* `true` if the generator function's control flow has reached the end.
* `false` if the generator function is able to produce more values.

`value`

The value yielded from the next `yield` expression.

### Exceptions

If the thrown exception is not caught by a `try...catch`, the `exception` passed to `throw()` will be thrown out from the generator function.

Description
-----------

The `throw()` method, when called, can be seen as if a `throw exception;` statement is inserted in the generator's body at the current suspended position, where `exception` is the exception passed to the `throw()` method. Therefore, in a typical flow, calling `throw(exception)` will cause the generator to throw. However, if the `yield` expression is wrapped in a `try...catch` block, the error may be caught and control flow can either resume after error handling, or exit gracefully.

Examples
--------

### Using throw()

The following example shows a simple generator and an error that is thrown using the `throw` method. An error can be caught by a `try...catch` block as usual.


```js
function\* gen() {
  while (true) {
    try {
      yield 42;
    } catch (e) {
      console.log("Error caught!");
    }
  }
}

const g = gen();
g.next();
// { value: 42, done: false }
g.throw(new Error("Something went wrong"));
// "Error caught!"
// { value: 42, done: false }
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-generator.prototype.throw |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `function*`
Reflect.getPrototypeOf()
========================

The **`Reflect.getPrototypeOf()`** static method is like `Object.getPrototypeOf()`. It returns the prototype of the specified object.

Try it
------

Syntax
------


```js
Reflect.getPrototypeOf(target)
```

### Parameters

`target`

The target object of which to get the prototype.

### Return value

The prototype of the given object, which may be an object or `null`.

### Exceptions

`TypeError`

Thrown if `target` is not an object.

Description
-----------

`Reflect.getPrototypeOf()` provides the reflective semantic of retrieving the prototype of an object. The only difference with `Object.getPrototypeOf()` is how non-object targets are handled. `Reflect.getPrototypeOf()` throws a `TypeError` if the target is not an object, while `Object.getPrototypeOf()` coerces it to an object.

`Reflect.getPrototypeOf()` invokes the `[[GetPrototypeOf]]` object internal method of `target`.

Examples
--------

### Using Reflect.getPrototypeOf()


```js
Reflect.getPrototypeOf({}); // Object.prototype
Reflect.getPrototypeOf(Object.prototype); // null
Reflect.getPrototypeOf(Object.create(null)); // null
```

### Difference with Object.getPrototypeOf()


```js
// Same result for Objects
Object.getPrototypeOf({}); // Object.prototype
Reflect.getPrototypeOf({}); // Object.prototype

// Both throw in ES5 for non-Objects
Object.getPrototypeOf("foo"); // Throws TypeError
Reflect.getPrototypeOf("foo"); // Throws TypeError

// In ES2015 only Reflect throws, Object coerces non-Objects
Object.getPrototypeOf("foo"); // String.prototype
Reflect.getPrototypeOf("foo"); // Throws TypeError

// To mimic the Object ES2015 behavior you need to coerce
Reflect.getPrototypeOf(Object("foo")); // String.prototype
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-reflect.getprototypeof |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Reflect.getPrototypeOf` in `core-js`
* `Reflect`
* `Object.getPrototypeOf()`
* `handler.getPrototypeOf()`