recursal/MDN huggingface dataset:
Object.getOwnPropertySymbols()
==============================

The **`Object.getOwnPropertySymbols()`** static method returns an array of all symbol properties found directly upon a given object.

Try it
------

Syntax
------


```js
Object.getOwnPropertySymbols(obj)
```

### Parameters

`obj`

The object whose symbol properties are to be returned.

### Return value

An array of all symbol properties found directly upon the given object.

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

Similar to `Object.getOwnPropertyNames()`, you can get all symbol properties of a given object as an array of symbols. Note that `Object.getOwnPropertyNames()` itself does not contain the symbol properties of an object and only the string properties.

As all objects have no own symbol properties initially, `Object.getOwnPropertySymbols()` returns an empty array unless you have set symbol properties on your object.

Examples
--------

### Using Object.getOwnPropertySymbols()


```js
const obj = {};
const a = Symbol("a");
const b = Symbol.for("b");

obj[a] = "localSymbol";
obj[b] = "globalSymbol";

const objectSymbols = Object.getOwnPropertySymbols(obj);

console.log(objectSymbols.length); // 2
console.log(objectSymbols); // [Symbol(a), Symbol(b)]
console.log(objectSymbols[0]); // Symbol(a)
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-object.getownpropertysymbols |

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

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

See also
--------

* Polyfill of `Object.getOwnPropertySymbols` in `core-js`
* `Object.getOwnPropertyNames()`
* `Symbol`
Object() constructor
====================

The **`Object()`** constructor turns the input into an object. Its behavior depends on the input's type.

Syntax
------


```js
new Object()
new Object(value)

Object()
Object(value)
```


**Note:** `Object()` can be called with or without `new`, but sometimes with different effects. See Return value.

### Parameters

`value` Optional

Any value.

### Return value

When the `Object()` constructor itself is called or constructed, its return value is an object:

* If the value is `null` or `undefined`, it creates and returns an empty object.
* If the value is an object already, it returns the value.
* Otherwise, it returns an object of a type that corresponds to the given value. For example, passing a `BigInt` primitive returns a `BigInt` wrapper object.

When `Object()` is constructed but `new.target` is not the `Object` constructor itself, the behavior is slightly different — it initializes a new object with `new.target.prototype` as its prototype. Any argument value is ignored. This may happen, for example, when `Object()` is implicitly called via `super()` in the constructor of a class that extends `Object`. In this case, even if you pass a number to `super()`, the `this` value inside the constructor does not become a `Number` instance.

Examples
--------

### Creating a new Object


```js
const o = new Object();
o.foo = 42;

console.log(o);
// { foo: 42 }
```

### Using Object given undefined and null types

The following examples store an empty `Object` object in `o`:


```js
const o = new Object();
```



```js
const o = new Object(undefined);
```



```js
const o = new Object(null);
```

### Obtaining wrapper objects for BigInt and Symbol

The `BigInt()` and `Symbol()` constructors throw an error when called with `new`, to prevent the common mistake of creating a wrapper object instead of the primitive value. The only way to create a wrapper object for these types is to call `Object()` with them:


```js
const numberObj = new Number(1);
console.log(typeof numberObj); // "object"

const bigintObj = Object(1n);
console.log(typeof bigintObj); // "object"

const symbolObj = Object(Symbol("foo"));
console.log(typeof symbolObj); // "object"
```

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

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

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

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

See also
--------

* Object initializer
Object.defineProperties()
=========================

 The **`Object.defineProperties()`** static method defines new or
 modifies existing properties directly on an object, returning the object.

Try it
------

Syntax
------


```js
Object.defineProperties(obj, props)
```

### Parameters

`obj`

The object on which to define or modify properties.

`props`

 An object whose keys represent the names of properties to be defined or modified and
 whose values are objects describing those properties. Each value in `props`
 must be either a data descriptor or an accessor descriptor; it cannot be both (see
 `Object.defineProperty()` for more details).


Data descriptors and accessor descriptors may optionally contain the following keys:

`configurable`

`true` if and only if the type of this property descriptor may be
 changed and if the property may be deleted from the corresponding object.
 **Defaults to `false`.**

`enumerable`

`true` if and only if this property shows up during enumeration of
 the properties on the corresponding object.
 **Defaults to `false`.**


A data descriptor also has the following optional keys:

`value`

 The value associated with the property. Can be any valid JavaScript value
 (number, object, function, etc.).
 **Defaults to `undefined`.**

`writable`

`true` if and only if the value associated with the property may be
 changed with an assignment operator.
 **Defaults to `false`.**


An accessor descriptor also has the following optional keys:

`get`

 A function which serves as a getter for the property, or `undefined`
 if there is no getter. The function's return value will be used as the value of
 the property.
 **Defaults to `undefined`.**

`set`

 A function which serves as a setter for the property, or `undefined`
 if there is no setter. The function will receive as its only argument the new
 value being assigned to the property.
 **Defaults to `undefined`.**



 If a descriptor has neither of `value`, `writable`,
 `get` and `set` keys, it is treated as a data descriptor. If a
 descriptor has both `value` or `writable` and `get`
 or `set` keys, an exception is thrown.


### Return value

The object that was passed to the function.

Examples
--------

### Using Object.defineProperties


```js
const obj = {};
Object.defineProperties(obj, {
  property1: {
    value: true,
    writable: true,
  },
  property2: {
    value: "Hello",
    writable: false,
  },
  // etc. etc.
});
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-object.defineproperties |

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

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

See also
--------

* Polyfill of `Object.defineProperties` in `core-js`
* `Object.defineProperty()`
* `Object.keys()`
* Enumerability and ownership of properties
RegExp.prototype.global
=======================

The **`global`** accessor property of `RegExp` instances returns whether or not the `g` flag is used with this regular expression.

Try it
------

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

`RegExp.prototype.global` has the value `true` if the `g` flag was used; otherwise, `false`. The `g` flag indicates that the regular expression should be tested against all possible matches in a string. Each call to `exec()` will update its `lastIndex` property, so that the next call to `exec()` will start at the next character.

Some methods, such as `String.prototype.matchAll()` and `String.prototype.replaceAll()`, will validate that, if the parameter is a regex, it is global. The regex's `@@match` and `@@replace` methods (called by `String.prototype.match()` and `String.prototype.replace()`) would also have different behaviors when the regex is global.

The set accessor of `global` is `undefined`. You cannot change this property directly.

Examples
--------

### Using global


```js
const regex = /foo/g;
console.log(regex.global); // true

const str = "fooexamplefoo";
const str1 = str.replace(regex, "");
console.log(str1); // example

const regex1 = /foo/;
const str2 = str.replace(regex1, "");
console.log(str2); // examplefoo
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-get-regexp.prototype.global |

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

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

See also
--------

* `RegExp.prototype.lastIndex`
* `RegExp.prototype.dotAll`
* `RegExp.prototype.hasIndices`
* `RegExp.prototype.ignoreCase`
* `RegExp.prototype.multiline`
* `RegExp.prototype.source`
* `RegExp.prototype.sticky`
* `RegExp.prototype.unicode`
RegExp.leftContext ($`)
=======================

**Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

**Note:** All `RegExp` static properties that expose the last match state globally are deprecated. See deprecated RegExp features for more information.

The **`RegExp.leftContext`** static accessor property returns the substring preceding the most recent match. `RegExp["$`"]` is an alias for this property.

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

Because `leftContext` is a static property of `RegExp`, you always use it as `RegExp.leftContext` or `RegExp["$`"]`, rather than as a property of a `RegExp` object you created.

The value of `leftContext` updates whenever a `RegExp` (but not a `RegExp` subclass) instance makes a successful match. If no matches have been made, `leftContext` is an empty string. The set accessor of `leftContext` is `undefined`, so you cannot change this property directly.

You cannot use the shorthand alias with the dot property accessor (`RegExp.$`` ), because ``` is not a valid identifier part, so this causes a `SyntaxError`. Use the bracket notation instead.

`$`` can also be used in the replacement string of `String.prototype.replace()`, but that's unrelated to the `RegExp["$`"]` legacy property.

Examples
--------

### Using leftContext and $`


```js
const re = /world/g;
re.test("hello world!");
RegExp.leftContext; // "hello "
RegExp["$`"]; // "hello "
```

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

| Specification |
| --- |
| Legacy RegExp features # additional-properties-of-the-regexp-constructor |

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

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

See also
--------

* `RegExp.input ($_)`
* `RegExp.lastMatch ($&)`
* `RegExp.lastParen ($+)`
* `RegExp.rightContext ($')`
* `RegExp.$1, …, RegExp.$9`
RegExp.prototype.toString()
===========================

The **`toString()`** method of `RegExp` instances returns a string representing this regular expression.

Try it
------

Syntax
------


```js
toString()
```

### Parameters

None.

### Return value

A string representing the given object.

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

The `RegExp` object overrides the `toString()` method of the `Object` object; it does not inherit `Object.prototype.toString()`. For `RegExp` objects, the `toString()` method returns a string representation of the regular expression.

In practice, it reads the regex's `source` and `flags` properties and returns a string in the form `/source/flags`. The `toString()` return value is guaranteed to be a parsable regex literal, although it may not be the exact same text as what was originally specified for the regex (for example, the flags may be reordered).

Examples
--------

### Using toString()

The following example displays the string value of a `RegExp` object:


```js
const myExp = new RegExp("a+b+c");
console.log(myExp.toString()); // '/a+b+c/'

const foo = new RegExp("bar", "g");
console.log(foo.toString()); // '/bar/g'
```

### Empty regular expressions and escaping

Since `toString()` accesses the `source` property, an empty regular expression returns the string `"/(?:)/"`, and line terminators such as `\n` are escaped. This makes the returned value always a valid regex literal.


```js
new RegExp().toString(); // "/(?:)/"

new RegExp("\n").toString() === "/\\n/"; // true
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-regexp.prototype.tostring |

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

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

See also
--------

* `Object.prototype.toString()`
RegExp.prototype.unicodeSets
============================

The **`unicodeSets`** accessor property of `RegExp` instances returns whether or not the `v` flag is used with this regular expression.

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

`RegExp.prototype.unicodeSets` has the value `true` if the `v` flag was used; otherwise, `false`. The `v` flag is an "upgrade" to the `u` flag that enables more Unicode-related features. ("v" is the next letter after "u" in the alphabet.) Because `u` and `v` interpret the same regex in incompatible ways, using both flags results in a `SyntaxError`. With the `v` flag, you get all features mentioned in the `u` flag description, plus:

* The `\p` escape sequence can be additionally used to match properties of strings, instead of just characters.
* The character class syntax is upgraded to allow intersection, union, and subtraction syntaxes, as well as matching multiple Unicode characters.
* The character class complement syntax `[^...]` constructs a complement class instead of negating the match result, avoiding some confusing behaviors with case-insensitive matching. For more information, see Complement classes and case-insensitive matching.

Some valid `u`-mode regexes become invalid in `v`-mode. Specifically, the character class syntax is different and some characters can no longer appear literally. For more information, see `v`-mode character class.

**Note:** The `v` mode does not interpret grapheme clusters as single characters; they are still multiple code points. For example, `/[🇺🇳]/v` is still able to match `"🇺"`.

The set accessor of `unicodeSets` is `undefined`. You cannot change this property directly.

Examples
--------

### Using the unicodeSets property


```js
const regex = /[\p{Script\_Extensions=Greek}&&\p{Letter}]/v;

console.log(regex.unicodeSets); // true
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-get-regexp.prototype.unicodesets |

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

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

See also
--------

* `RegExp.prototype.lastIndex`
* `RegExp.prototype.dotAll`
* `RegExp.prototype.global`
* `RegExp.prototype.hasIndices`
* `RegExp.prototype.ignoreCase`
* `RegExp.prototype.multiline`
* `RegExp.prototype.source`
* `RegExp.prototype.sticky`
* `RegExp.prototype.unicode`
* RegExp v flag with set notation and properties of strings on v8.dev (2022)
RegExp.prototype[@@search]()
============================

The **`[@@search]()`** method of `RegExp` instances specifies how `String.prototype.search` should behave.

Try it
------

Syntax
------


```js
regexp[Symbol.search](str)
```

### Parameters

`str`

A `String` that is a target of the search.

### Return value

The index of the first match between the regular expression and the given string, or `-1` if no match was found.

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

This method is called internally in `String.prototype.search()`. For example, the following two examples return the same result.


```js
"abc".search(/a/);

/a/[Symbol.search]("abc");
```


This method does not copy the regular expression, unlike `@@split` or `@@matchAll`. However, unlike `@@match` or `@@replace`, it will set `lastIndex` to 0 when execution starts and restore it to the previous value when it exits, therefore generally avoiding side effects. This means that the `g` flag has no effect with this method, and it always returns the first match in the string even when `lastIndex` is non-zero. This also means sticky regexps will always search strictly at the beginning of the string.


```js
const re = /[abc]/g;
re.lastIndex = 2;
console.log("abc".search(re)); // 0

const re2 = /[bc]/y;
re2.lastIndex = 1;
console.log("abc".search(re2)); // -1
console.log("abc".match(re2)); // [ 'b' ]
```


`@@search` always calls the regex's `exec()` method exactly once, and returns the `index` property of the result, or `-1` if the result is `null`.

This method exists for customizing the search behavior in `RegExp` subclasses.

Examples
--------

### Direct call

This method can be used in almost the same way as `String.prototype.search()`, except for the different value of `this` and the different arguments order.


```js
const re = /-/g;
const str = "2016-01-02";
const result = re[Symbol.search](str);
console.log(result); // 4
```

### Using @@search in subclasses

Subclasses of `RegExp` can override `[@@search]()` method to modify the behavior.


```js
class MyRegExp extends RegExp {
  constructor(str) {
    super(str);
    this.pattern = str;
  }
  [Symbol.search](str) {
    return str.indexOf(this.pattern);
  }
}

const re = new MyRegExp("a+b");
const str = "ab a+b";
const result = str.search(re); // String.prototype.search calls re[@@search].
console.log(result); // 3
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-regexp.prototype-@@search |

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

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

See also
--------

* Polyfill of `RegExp.prototype[@@search]` in `core-js`
* `String.prototype.search()`
* `RegExp.prototype[@@match]()`
* `RegExp.prototype[@@matchAll]()`
* `RegExp.prototype[@@replace]()`
* `RegExp.prototype[@@split]()`
* `RegExp.prototype.exec()`
* `RegExp.prototype.test()`
* `Symbol.search`
RegExp.prototype.source
=======================

The **`source`** accessor property of `RegExp` instances returns a string containing the source text of this regular expression, without the two forward slashes on both sides or any flags.

Try it
------

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

Conceptually, the `source` property is the text between the two forward slashes in the regular expression literal. The language requires the returned string to be properly escaped, so that when the `source` is concatenated with a forward slash on both ends, it would form a parsable regex literal. For example, for `new RegExp("/")`, the `source` is `\\/`, because if it generates `/`, the resulting literal becomes `///`, which is a line comment. Similarly, all line terminators will be escaped because line terminator *characters* would break up the regex literal. There's no requirement for other characters, as long as the result is parsable. For empty regular expressions, the string `(?:)` is returned.

Examples
--------

### Using source


```js
const regex = /fooBar/gi;

console.log(regex.source); // "fooBar", doesn't contain /.../ and "gi".
```

### Empty regular expressions and escaping


```js
new RegExp().source; // "(?:)"

new RegExp("\n").source === "\\n"; // true, starting with ES5
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-get-regexp.prototype.source |

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

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

See also
--------

* `RegExp.prototype.flags`
RegExp.input ($\_)
==================

**Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

**Note:** All `RegExp` static properties that expose the last match state globally are deprecated. See deprecated RegExp features for more information.

The **`RegExp.input`** static accessor property returns the string against which a regular expression is matched. `RegExp.$_` is an alias for this property.

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

Because `input` is a static property of `RegExp`, you always use it as `RegExp.input` or `RegExp.$_`, rather than as a property of a `RegExp` object you created.

The value of `input` updates whenever a `RegExp` (but not a `RegExp` subclass) instance makes a successful match. If no matches have been made, `input` is an empty string. You can set the value of `input`, but this does not affect other behaviors of the regex, and the value will be overwritten again when the next successful match is made.

Examples
--------

### Using input and $\_


```js
const re = /hi/g;
re.test("hi there!");
RegExp.input; // "hi there!"
re.test("foo"); // new test, non-matching
RegExp.$_; // "hi there!"
re.test("hi world!"); // new test, matching
RegExp.$_; // "hi world!"
```

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

| Specification |
| --- |
| Legacy RegExp features # additional-properties-of-the-regexp-constructor |

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

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

See also
--------

* `RegExp.lastMatch ($&)`
* `RegExp.lastParen ($+)`
* `RegExp.leftContext ($`)`
* `RegExp.rightContext ($')`
* `RegExp.$1, …, RegExp.$9`
RegExp.prototype.compile()
==========================

**Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

**Note:** The `compile()` method is only specified for compatibility reasons. Using `compile()` causes the otherwise immutable regex source and flags to become mutable, which may break user expectations. You can use the `RegExp()` constructor to construct a new regular expression object instead.

The **`compile()`** method of `RegExp` instances is used to recompile a regular expression with new source and flags after the `RegExp` object has already been created.

Syntax
------


```js
compile(pattern, flags)
```

### Parameters

`pattern`

The text of the regular expression.

`flags`

Any combination of flag values.

### Return value

None (`undefined`).

Examples
--------

### Using compile()

The following example shows how to recompile a regular expression with a new pattern and a new flag.


```js
const regexObj = new RegExp("foo", "gi");
regexObj.compile("new foo", "g");
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-regexp.prototype.compile |

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

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

See also
--------

* `RegExp`