chunk_id stringlengths 36 36 | source stringclasses 35
values | source_url stringlengths 0 290 | upstream_license stringclasses 1
value | document_id stringlengths 36 36 | chunk_index int64 0 324k | retrieved_at stringclasses 2
values | chunker_version stringclasses 4
values | content_hash stringlengths 15 64 | content stringlengths 50 44.7k | namespace stringclasses 9
values | source_name stringclasses 35
values | raw_text stringlengths 50 44.7k | cleaned_text stringlengths 50 44.7k | tags stringclasses 49
values | collection_name stringclasses 11
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
b92844aa-32c9-416c-9466-7d504ffe10b3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/find-matching-keys.md | unknown | cd81a170-6ec5-43ca-9503-037021bcbcd3 | 1 | SemanticChunker@1.0.0 | 163ba3e2f6ac90e9dca3272e9bd83746397fd37c3aaa1629f1e18f5841e953d5 | [Find all matching keys]
## Find all matching keys
Using `Object.keys()`, you can get all the keys of an object as an array. You can then use `Array.prototype.filter()` to test each key-value pair and return all keys that match the given condition.
```js
const findKeys = (obj, fn) =>
Object.keys(obj).filter(key => ... | unknown | unknown | [Find all matching keys]
## Find all matching keys
Using `Object.keys()`, you can get all the keys of an object as an array. You can then use `Array.prototype.filter()` to test each key-value pair and return all keys that match the given condition.
```js
const findKeys = (obj, fn) =>
Object.keys(obj).filter(key => ... | [Find all matching keys]
## Find all matching keys
Using `Object.keys()`, you can get all the keys of an object as an array. You can then use `Array.prototype.filter()` to test each key-value pair and return all keys that match the given condition.
```js
const findKeys = (obj, fn) =>
Object.keys(obj).filter(key => ... | code_snippets | ||
4e2df47f-b3c4-4279-9965-eaf5ee94e0e2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/functional-programming-introduction.md | unknown | 0cf2fe4c-58f8-494c-aa15-b89814ad8109 | 6 | SemanticChunker@1.0.0 | 2dce6a80bd76352dfee2361f0db1ab2cab84e189dbe7d86b0096fe0387213671 | [Core concepts of functional programming > Benefits of functional programming]
## Benefits of functional programming
Functional programming has many benefits. The main one that people often talk about is that it's **easier to reason about code** written in a functional style. This is because pure functions don't have... | unknown | unknown | [Core concepts of functional programming > Benefits of functional programming]
## Benefits of functional programming
Functional programming has many benefits. The main one that people often talk about is that it's **easier to reason about code** written in a functional style. This is because pure functions don't have... | [Core concepts of functional programming > Benefits of functional programming]
## Benefits of functional programming
Functional programming has many benefits. The main one that people often talk about is that it's **easier to reason about code** written in a functional style. This is because pure functions don't have... | code_snippets | ||
4ec95990-0e7a-42bf-8e64-6fb9334d7bc6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/functional-programming-introduction.md | unknown | 0cf2fe4c-58f8-494c-aa15-b89814ad8109 | 4 | SemanticChunker@1.0.0 | 5dbae9fdcf4f3c74909b5fec933179dfea0d48a6c908c22b403f31133029c14c | [Pure functions > Higher-order functions]
### Higher-order functions
A [higher-order function](/js/s/higher-order-functions) is a function that either takes a **function as an argument** or **returns a function**. Higher-order functions are very common in functional programming and are used to create more complex fun... | unknown | unknown | [Pure functions > Higher-order functions]
### Higher-order functions
A [higher-order function](/js/s/higher-order-functions) is a function that either takes a **function as an argument** or **returns a function**. Higher-order functions are very common in functional programming and are used to create more complex fun... | [Pure functions > Higher-order functions]
### Higher-order functions
A [higher-order function](/js/s/higher-order-functions) is a function that either takes a **function as an argument** or **returns a function**. Higher-order functions are very common in functional programming and are used to create more complex fun... | code_snippets | ||
5965cb3d-9519-405b-8117-f642b1425fb3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/functional-programming-introduction.md | unknown | 0cf2fe4c-58f8-494c-aa15-b89814ad8109 | 5 | SemanticChunker@1.0.0 | ccf0639a97ee3b17f843edd1c43e655c28abe8d84b653c7453a5a074352c1301 | [Pure functions > Recursion]
### Recursion
[Recursion](/js/s/recursion) is a technique where **a function calls itself**. It's a very powerful technique that can be used to solve many problems in functional programming.
```js
// Recursive function
const factorial = num => {
if (num === 0) return 1;
return num * fa... | unknown | unknown | [Pure functions > Recursion]
### Recursion
[Recursion](/js/s/recursion) is a technique where **a function calls itself**. It's a very powerful technique that can be used to solve many problems in functional programming.
```js
// Recursive function
const factorial = num => {
if (num === 0) return 1;
return num * fa... | [Pure functions > Recursion]
### Recursion
[Recursion](/js/s/recursion) is a technique where **a function calls itself**. It's a very powerful technique that can be used to solve many problems in functional programming.
```js
// Recursive function
const factorial = num => {
if (num === 0) return 1;
return num * fa... | code_snippets | ||
7fc5ca26-fc84-43a4-b547-2d7c96185af0 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/functional-programming-introduction.md | unknown | 0cf2fe4c-58f8-494c-aa15-b89814ad8109 | 2 | SemanticChunker@1.0.0 | 397e894034967546287916748ce8f4eed95215d2dac6bc6996b1a38eed644dad | [Core concepts of functional programming > Pure functions]
### Pure functions
A [pure function](/js/s/pure-functions) is a function that **always returns the same output for the same input** and has **no side effects**. This means that a pure function will not modify any external state or data. Pure functions are the... | unknown | unknown | [Core concepts of functional programming > Pure functions]
### Pure functions
A [pure function](/js/s/pure-functions) is a function that **always returns the same output for the same input** and has **no side effects**. This means that a pure function will not modify any external state or data. Pure functions are the... | [Core concepts of functional programming > Pure functions]
### Pure functions
A [pure function](/js/s/pure-functions) is a function that **always returns the same output for the same input** and has **no side effects**. This means that a pure function will not modify any external state or data. Pure functions are the... | code_snippets | ||
9da40366-f7b5-436f-a249-80dfc1a2fbbf | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/functional-programming-introduction.md | unknown | 0cf2fe4c-58f8-494c-aa15-b89814ad8109 | 1 | SemanticChunker@1.0.0 | 532c95bfee016c9e1d94ed20204b75d275c683d6f857c7d962219b0affcdf32f | [Core concepts of functional programming]
## Core concepts of functional programming
Functional programming is based on a few core concepts that are used to solve problems in a functional way. Some of these concepts are explained below, but I **strongly encourage you to read the linked articles** for a more in-depth ... | unknown | unknown | [Core concepts of functional programming]
## Core concepts of functional programming
Functional programming is based on a few core concepts that are used to solve problems in a functional way. Some of these concepts are explained below, but I **strongly encourage you to read the linked articles** for a more in-depth ... | [Core concepts of functional programming]
## Core concepts of functional programming
Functional programming is based on a few core concepts that are used to solve problems in a functional way. Some of these concepts are explained below, but I **strongly encourage you to read the linked articles** for a more in-depth ... | code_snippets | ||
a0b1538e-d1b3-4583-8e8c-7a60579a926f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/functional-programming-introduction.md | unknown | 0cf2fe4c-58f8-494c-aa15-b89814ad8109 | 0 | SemanticChunker@1.0.0 | 53e697f6cea5342cc7facdd93a8997c110ca7e4a9f6ab5f0f3230cf3b54abe79 | ---
title: An introduction to functional programming
shortTitle: Functional programming introduction
language: javascript
tags: [function]
cover: driftwood
excerpt: A short introduction to the functional programming paradigm.
listed: true
dateModified: 2023-12-30
journeyId: js/functional-programming
---
Functional pro... | unknown | unknown | ---
title: An introduction to functional programming
shortTitle: Functional programming introduction
language: javascript
tags: [function]
cover: driftwood
excerpt: A short introduction to the functional programming paradigm.
listed: true
dateModified: 2023-12-30
journeyId: js/functional-programming
---
Functional pro... | ---
title: An introduction to functional programming
shortTitle: Functional programming introduction
language: javascript
tags: [function]
cover: driftwood
excerpt: A short introduction to the functional programming paradigm.
listed: true
dateModified: 2023-12-30
journeyId: js/functional-programming
---
Functional pro... | code_snippets | ||
ac7bb625-db55-4379-a054-c9ce0b1b0913 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/functional-programming-introduction.md | unknown | 0cf2fe4c-58f8-494c-aa15-b89814ad8109 | 3 | SemanticChunker@1.0.0 | 35994816be92b14caf4984801bd48e065b49f3372c70886ed7543a9c7a4d90c4 | [Pure functions > Immutability]
### Immutability
[Immutability](/js/s/immutability) means that once a value is created, it **cannot be changed**. This is in contrast to mutable data, which can be changed after it's created. Immutability is a core concept in functional programming and is closely related to pure functi... | unknown | unknown | [Pure functions > Immutability]
### Immutability
[Immutability](/js/s/immutability) means that once a value is created, it **cannot be changed**. This is in contrast to mutable data, which can be changed after it's created. Immutability is a core concept in functional programming and is closely related to pure functi... | [Pure functions > Immutability]
### Immutability
[Immutability](/js/s/immutability) means that once a value is created, it **cannot be changed**. This is in contrast to mutable data, which can be changed after it's created. Immutability is a core concept in functional programming and is closely related to pure functi... | code_snippets | ||
1e1ef495-5077-4c5e-a0cd-7d30955f5a28 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/gcd-lcm.md | unknown | 605029af-aef3-4cf5-9af8-b381e962e2b2 | 2 | SemanticChunker@1.0.0 | 306e5a6d8c511bcbb7f6d879338dde7a199a31abd38aafdd15024a2907ddd69c | [Greatest common divisor > The Euclidean algorithm]
### The Euclidean algorithm
The **Euclidean algorithm** is an efficient method for computing the GCD of **two numbers**. This, in practice, means **recursively** applying the observation that `gcd(a, b) = gcd(b, a % b)` until `b` is **zero**. When `b` is zero, we ha... | unknown | unknown | [Greatest common divisor > The Euclidean algorithm]
### The Euclidean algorithm
The **Euclidean algorithm** is an efficient method for computing the GCD of **two numbers**. This, in practice, means **recursively** applying the observation that `gcd(a, b) = gcd(b, a % b)` until `b` is **zero**. When `b` is zero, we ha... | [Greatest common divisor > The Euclidean algorithm]
### The Euclidean algorithm
The **Euclidean algorithm** is an efficient method for computing the GCD of **two numbers**. This, in practice, means **recursively** applying the observation that `gcd(a, b) = gcd(b, a % b)` until `b` is **zero**. When `b` is zero, we ha... | code_snippets | ||
2864689c-b21a-44ab-b0a9-acb7f499820a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/gcd-lcm.md | unknown | 605029af-aef3-4cf5-9af8-b381e962e2b2 | 6 | SemanticChunker@1.0.0 | 10385f92fc35a052b419eabbd887e72036e246404cb75ded3c58823d030a93a1 | [Least common multiple > Least common multiple of more than two numbers]
### Least common multiple of more than two numbers
Similarly to the GCD, the LCM of more than two numbers can be calculated with the help of `Array.prototype.reduce()`. Start by calculating the LCM of the **first two numbers**, then keep applyin... | unknown | unknown | [Least common multiple > Least common multiple of more than two numbers]
### Least common multiple of more than two numbers
Similarly to the GCD, the LCM of more than two numbers can be calculated with the help of `Array.prototype.reduce()`. Start by calculating the LCM of the **first two numbers**, then keep applyin... | [Least common multiple > Least common multiple of more than two numbers]
### Least common multiple of more than two numbers
Similarly to the GCD, the LCM of more than two numbers can be calculated with the help of `Array.prototype.reduce()`. Start by calculating the LCM of the **first two numbers**, then keep applyin... | code_snippets | ||
778e5768-4144-40c3-991d-3d0286fe4c1a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/gcd-lcm.md | unknown | 605029af-aef3-4cf5-9af8-b381e962e2b2 | 0 | SemanticChunker@1.0.0 | ef33f0a80818ff83dc4464bd11d28a8f84bb5f3aa1cb72066c8aedc4376d4139 | ---
title: How can I calculate the greatest common divisor & least common multiple in JavaScript?
shortTitle: Greatest common divisor & least common multiple
language: javascript
tags: [math,algorithm,recursion]
cover: migrating-birds
excerpt: Use JavaScript to calculate the greatest common divisor and least common mul... | unknown | unknown | ---
title: How can I calculate the greatest common divisor & least common multiple in JavaScript?
shortTitle: Greatest common divisor & least common multiple
language: javascript
tags: [math,algorithm,recursion]
cover: migrating-birds
excerpt: Use JavaScript to calculate the greatest common divisor and least common mul... | ---
title: How can I calculate the greatest common divisor & least common multiple in JavaScript?
shortTitle: Greatest common divisor & least common multiple
language: javascript
tags: [math,algorithm,recursion]
cover: migrating-birds
excerpt: Use JavaScript to calculate the greatest common divisor and least common mul... | code_snippets | ||
9c59b91b-7a0d-4e2b-9068-97b3eeff6dd4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/gcd-lcm.md | unknown | 605029af-aef3-4cf5-9af8-b381e962e2b2 | 5 | SemanticChunker@1.0.0 | 158525010f48f42091751d5c19843e5a9ea9c0fc347520764fd749d4338f3287 | [Least common multiple > Least common multiple of two numbers]
### Least common multiple of two numbers
The LCM of two numbers can be calculated by using the **greatest common divisor** (GCD) formula and the fact that `lcm(x, y) = x * y / gcd(x, y)`.
<latex-expression>
```math
lcm(x, y) = \frac{x \cdot y}{gcd(x, y)... | unknown | unknown | [Least common multiple > Least common multiple of two numbers]
### Least common multiple of two numbers
The LCM of two numbers can be calculated by using the **greatest common divisor** (GCD) formula and the fact that `lcm(x, y) = x * y / gcd(x, y)`.
<latex-expression>
```math
lcm(x, y) = \frac{x \cdot y}{gcd(x, y)... | [Least common multiple > Least common multiple of two numbers]
### Least common multiple of two numbers
The LCM of two numbers can be calculated by using the **greatest common divisor** (GCD) formula and the fact that `lcm(x, y) = x * y / gcd(x, y)`.
<latex-expression>
```math
lcm(x, y) = \frac{x \cdot y}{gcd(x, y)... | code_snippets | ||
abf480d0-1c24-417d-905b-62a10599adaf | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/gcd-lcm.md | unknown | 605029af-aef3-4cf5-9af8-b381e962e2b2 | 4 | SemanticChunker@1.0.0 | 706ea7378b82bc034005571e3b16582776fa1828e802f25be644b8e840158460 | [Greatest common divisor > Least common multiple]
## Least common multiple
The [least common multiple](https://en.wikipedia.org/wiki/Least_common_multiple) (**LCM**) of two numbers is the smallest positive integer that is perfectly divisible by the two given numbers. | unknown | unknown | [Greatest common divisor > Least common multiple]
## Least common multiple
The [least common multiple](https://en.wikipedia.org/wiki/Least_common_multiple) (**LCM**) of two numbers is the smallest positive integer that is perfectly divisible by the two given numbers. | [Greatest common divisor > Least common multiple]
## Least common multiple
The [least common multiple](https://en.wikipedia.org/wiki/Least_common_multiple) (**LCM**) of two numbers is the smallest positive integer that is perfectly divisible by the two given numbers. | code_snippets | ||
c89e4756-3092-4d67-a449-fb63964a1a01 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/gcd-lcm.md | unknown | 605029af-aef3-4cf5-9af8-b381e962e2b2 | 3 | SemanticChunker@1.0.0 | e72afa1262a7f4024b5489930d8dc63e4a806fa17537058fe492083b07082041 | [The Euclidean algorithm > Greatest common divisor of more than two numbers]
### Greatest common divisor of more than two numbers
The GCD of more than two numbers can be calculated by calculating the GCD of each **pair of numbers**. On top of the recursive function, we can use `Array.prototype.reduce()` to apply the ... | unknown | unknown | [The Euclidean algorithm > Greatest common divisor of more than two numbers]
### Greatest common divisor of more than two numbers
The GCD of more than two numbers can be calculated by calculating the GCD of each **pair of numbers**. On top of the recursive function, we can use `Array.prototype.reduce()` to apply the ... | [The Euclidean algorithm > Greatest common divisor of more than two numbers]
### Greatest common divisor of more than two numbers
The GCD of more than two numbers can be calculated by calculating the GCD of each **pair of numbers**. On top of the recursive function, we can use `Array.prototype.reduce()` to apply the ... | code_snippets | ||
d512a285-bde5-4107-b138-72b53e6fecee | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/gcd-lcm.md | unknown | 605029af-aef3-4cf5-9af8-b381e962e2b2 | 1 | SemanticChunker@1.0.0 | e87586e1e4aaba4cd201df8b938be4b378b490b25cb621db0994096a6a88d0ca | [Greatest common divisor]
## Greatest common divisor
The [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) (**GCD**), of two or more integers is the largest positive integer that divides each of the integers. | unknown | unknown | [Greatest common divisor]
## Greatest common divisor
The [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) (**GCD**), of two or more integers is the largest positive integer that divides each of the integers. | [Greatest common divisor]
## Greatest common divisor
The [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) (**GCD**), of two or more integers is the largest positive integer that divides each of the integers. | code_snippets | ||
01597892-ac62-4de7-99db-4cb585e2292a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-call-apply-bind.md | unknown | f0864880-3a71-47d5-8441-ebcd76415a96 | 1 | SemanticChunker@1.0.0 | a8c021859716eceeb2d673445df0169edecaf34e504c019eda125d76aa36633b | [Function methods]
## Function methods
JavaScript functions are **first-class objects**, which means they can be passed around like any other object. They can also have properties and methods, and can be passed as arguments to other functions. The `Function` object has several methods, including `call()`, `apply()` a... | unknown | unknown | [Function methods]
## Function methods
JavaScript functions are **first-class objects**, which means they can be passed around like any other object. They can also have properties and methods, and can be passed as arguments to other functions. The `Function` object has several methods, including `call()`, `apply()` a... | [Function methods]
## Function methods
JavaScript functions are **first-class objects**, which means they can be passed around like any other object. They can also have properties and methods, and can be passed as arguments to other functions. The `Function` object has several methods, including `call()`, `apply()` a... | code_snippets | ||
271be4aa-9168-4483-916d-d318f196f886 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-call-apply-bind.md | unknown | f0864880-3a71-47d5-8441-ebcd76415a96 | 4 | SemanticChunker@1.0.0 | 764753160bd35106ea07402ae3755b5b0cbe217d2dba6aebcccb7600807e2947 | [Function methods > `Function.prototype.bind()`]
## `Function.prototype.bind()`
`Function.prototype.bind()` is slightly different from the previous two methods. Instead of calling a function with the given `this` context and returning the result, it returns a function with its `this` context bound and any arguments p... | unknown | unknown | [Function methods > `Function.prototype.bind()`]
## `Function.prototype.bind()`
`Function.prototype.bind()` is slightly different from the previous two methods. Instead of calling a function with the given `this` context and returning the result, it returns a function with its `this` context bound and any arguments p... | [Function methods > `Function.prototype.bind()`]
## `Function.prototype.bind()`
`Function.prototype.bind()` is slightly different from the previous two methods. Instead of calling a function with the given `this` context and returning the result, it returns a function with its `this` context bound and any arguments p... | code_snippets | ||
6815200a-a6a2-4b03-9b86-5b92b3fe3985 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-call-apply-bind.md | unknown | f0864880-3a71-47d5-8441-ebcd76415a96 | 3 | SemanticChunker@1.0.0 | 394e04b5041164bb39007870dd81b5b1b73fdbf165e92027509604255205c2b9 | [Function methods > `Function.prototype.apply()`]
## `Function.prototype.apply()`
`Function.prototype.apply()` is almost identical to `Function.prototype.call()` in the sense that it calls a function with a given `this` context, however it requires arguments to be provided as an **array**. For example:
```js
functio... | unknown | unknown | [Function methods > `Function.prototype.apply()`]
## `Function.prototype.apply()`
`Function.prototype.apply()` is almost identical to `Function.prototype.call()` in the sense that it calls a function with a given `this` context, however it requires arguments to be provided as an **array**. For example:
```js
functio... | [Function methods > `Function.prototype.apply()`]
## `Function.prototype.apply()`
`Function.prototype.apply()` is almost identical to `Function.prototype.call()` in the sense that it calls a function with a given `this` context, however it requires arguments to be provided as an **array**. For example:
```js
functio... | code_snippets | ||
a0a2ac10-54bc-4793-999c-1e1c8386843a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-call-apply-bind.md | unknown | f0864880-3a71-47d5-8441-ebcd76415a96 | 7 | SemanticChunker@1.0.0 | 82a9856c12f4cc393994682b30adc26d6445282ed43d2ec681cb8c245541f251 | [Using function methods in practice > Bind all object methods]
### Bind all object methods
Similarly, you can bind **all methods** of an object to the object itself, overwriting the existing method. The technique is the same as before, but you need to use `Array.prototype.forEach()` to iterate over the given methods.... | unknown | unknown | [Using function methods in practice > Bind all object methods]
### Bind all object methods
Similarly, you can bind **all methods** of an object to the object itself, overwriting the existing method. The technique is the same as before, but you need to use `Array.prototype.forEach()` to iterate over the given methods.... | [Using function methods in practice > Bind all object methods]
### Bind all object methods
Similarly, you can bind **all methods** of an object to the object itself, overwriting the existing method. The technique is the same as before, but you need to use `Array.prototype.forEach()` to iterate over the given methods.... | code_snippets | ||
c1594990-c852-4c13-b568-f47a083c8c98 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-call-apply-bind.md | unknown | f0864880-3a71-47d5-8441-ebcd76415a96 | 2 | SemanticChunker@1.0.0 | ecc604a0cdaec52d1b9d051598555d81da0189e98021f9a188618694cc937209 | [Function methods > `Function.prototype.call()`]
## `Function.prototype.call()`
`Function.prototype.call()` is used to call a function with a given `this` context and any arguments provided **individually**. For example:
```js
function printThisAndData(...data) {
console.log(this.data, ...data);
}
const obj = { da... | unknown | unknown | [Function methods > `Function.prototype.call()`]
## `Function.prototype.call()`
`Function.prototype.call()` is used to call a function with a given `this` context and any arguments provided **individually**. For example:
```js
function printThisAndData(...data) {
console.log(this.data, ...data);
}
const obj = { da... | [Function methods > `Function.prototype.call()`]
## `Function.prototype.call()`
`Function.prototype.call()` is used to call a function with a given `this` context and any arguments provided **individually**. For example:
```js
function printThisAndData(...data) {
console.log(this.data, ...data);
}
const obj = { da... | code_snippets | ||
db580eab-8a5b-4e82-ae91-1ae49045ad0a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-call-apply-bind.md | unknown | f0864880-3a71-47d5-8441-ebcd76415a96 | 5 | SemanticChunker@1.0.0 | c4392c52b2ead8e22ca7c29d454dffa6eb6eee447e4ae1dd0c1b587ee48a9e82 | [Function methods > Using function methods in practice]
## Using function methods in practice
Knowing how these methods work is fine, but where would you use them in real life? Some examples include binding a method to an object, calling a function with a specific context, or calling a function with a specific set of... | unknown | unknown | [Function methods > Using function methods in practice]
## Using function methods in practice
Knowing how these methods work is fine, but where would you use them in real life? Some examples include binding a method to an object, calling a function with a specific context, or calling a function with a specific set of... | [Function methods > Using function methods in practice]
## Using function methods in practice
Knowing how these methods work is fine, but where would you use them in real life? Some examples include binding a method to an object, calling a function with a specific context, or calling a function with a specific set of... | code_snippets | ||
dc977179-5a00-4f05-a94f-05d570578943 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-call-apply-bind.md | unknown | f0864880-3a71-47d5-8441-ebcd76415a96 | 6 | SemanticChunker@1.0.0 | a8c9404e025b7d787ce3ca2a1546991cd2b8365a931213d86c6c9381e8a4bcb0 | [Using function methods in practice > Bind a method to an object]
### Bind a method to an object
You can use `Function.prototype.apply()` to create a function that invokes the method at a **given key** of an object, optionally prepending any additional supplied parameters to the arguments.
```js
const bindKey = (con... | unknown | unknown | [Using function methods in practice > Bind a method to an object]
### Bind a method to an object
You can use `Function.prototype.apply()` to create a function that invokes the method at a **given key** of an object, optionally prepending any additional supplied parameters to the arguments.
```js
const bindKey = (con... | [Using function methods in practice > Bind a method to an object]
### Bind a method to an object
You can use `Function.prototype.apply()` to create a function that invokes the method at a **given key** of an object, optionally prepending any additional supplied parameters to the arguments.
```js
const bindKey = (con... | code_snippets | ||
ec48f01a-7483-4780-b462-311cf07e403a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-call-apply-bind.md | unknown | f0864880-3a71-47d5-8441-ebcd76415a96 | 8 | SemanticChunker@1.0.0 | 25d5f7f1af82f2ade51dd9959c08cfb8bafd8c8da5e4db92d727a009ee56bfab | [Using function methods in practice > Bind function context]
### Bind function context
You can also create a function that invokes a given function with a **specific context**, optionally prepending any additional supplied parameters to the arguments. Same as before, use `Function.prototype.apply()` to apply the give... | unknown | unknown | [Using function methods in practice > Bind function context]
### Bind function context
You can also create a function that invokes a given function with a **specific context**, optionally prepending any additional supplied parameters to the arguments. Same as before, use `Function.prototype.apply()` to apply the give... | [Using function methods in practice > Bind function context]
### Bind function context
You can also create a function that invokes a given function with a **specific context**, optionally prepending any additional supplied parameters to the arguments. Same as before, use `Function.prototype.apply()` to apply the give... | code_snippets | ||
fa7e8390-9b33-4a70-9bfa-e0f247164dca | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-call-apply-bind.md | unknown | f0864880-3a71-47d5-8441-ebcd76415a96 | 0 | SemanticChunker@1.0.0 | a09d1dae58ad74845a48553368bc04b37ad7b60de62e94ca1d313ce45116d423 | ---
title: JavaScript function methods - call(), apply() and bind()
shortTitle: Function methods - call, apply, bind
language: javascript
tags: [function]
cover: canoe
excerpt: Learn everything you need to know about JavaScript's `call()`, `apply()` and `bind()` in this short guide.
listed: true
dateModified: 2024-02-2... | unknown | unknown | ---
title: JavaScript function methods - call(), apply() and bind()
shortTitle: Function methods - call, apply, bind
language: javascript
tags: [function]
cover: canoe
excerpt: Learn everything you need to know about JavaScript's `call()`, `apply()` and `bind()` in this short guide.
listed: true
dateModified: 2024-02-2... | ---
title: JavaScript function methods - call(), apply() and bind()
shortTitle: Function methods - call, apply, bind
language: javascript
tags: [function]
cover: canoe
excerpt: Learn everything you need to know about JavaScript's `call()`, `apply()` and `bind()` in this short guide.
listed: true
dateModified: 2024-02-2... | code_snippets | ||
3072db9e-6ad5-48e6-bd92-11d9372e35f9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-composition.md | unknown | 221005fc-ea4f-422f-bcd5-c42083731c19 | 2 | SemanticChunker@1.0.0 | 854bfb26d20f9e5b675f174dd9e4113bc736eaca6e15fc9ee9decfa99daad426 | [Compose functions > Pipe functions]
## Pipe functions
If right-to-left function composition sounds counterintuitive to you, you can easily create a `pipe()` function that performs **left-to-right** function composition. The implementation is almost identical to the previous one, except that we need to **reverse the ... | unknown | unknown | [Compose functions > Pipe functions]
## Pipe functions
If right-to-left function composition sounds counterintuitive to you, you can easily create a `pipe()` function that performs **left-to-right** function composition. The implementation is almost identical to the previous one, except that we need to **reverse the ... | [Compose functions > Pipe functions]
## Pipe functions
If right-to-left function composition sounds counterintuitive to you, you can easily create a `pipe()` function that performs **left-to-right** function composition. The implementation is almost identical to the previous one, except that we need to **reverse the ... | code_snippets | ||
8e130ed2-57b2-411e-ab24-695a5b9fda1e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-composition.md | unknown | 221005fc-ea4f-422f-bcd5-c42083731c19 | 1 | SemanticChunker@1.0.0 | baa5355b4c886a11250df8bf4a9b0aafbf3de6c566fb19f12b42d914899482fd | [Compose functions]
## Compose functions
Creating a `compose()` function is relatively simple, as long as we understand how it should work. Similar to math, function composition in JavaScript is performed **from right to left**. In order to iterate over the functions we can simply use `Array.prototype.reduce()` and p... | unknown | unknown | [Compose functions]
## Compose functions
Creating a `compose()` function is relatively simple, as long as we understand how it should work. Similar to math, function composition in JavaScript is performed **from right to left**. In order to iterate over the functions we can simply use `Array.prototype.reduce()` and p... | [Compose functions]
## Compose functions
Creating a `compose()` function is relatively simple, as long as we understand how it should work. Similar to math, function composition in JavaScript is performed **from right to left**. In order to iterate over the functions we can simply use `Array.prototype.reduce()` and p... | code_snippets | ||
902d6c0d-8328-4318-a9f4-45465b5b69fc | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-composition.md | unknown | 221005fc-ea4f-422f-bcd5-c42083731c19 | 0 | SemanticChunker@1.0.0 | 73b9606f9d7e892c0f8241c6b0713ff99a598f41cfae1219f46c1ef9445fc2b3 | ---
title: Function composition in JavaScript
shortTitle: Function composition
language: javascript
tags: [function]
cover: digital-nomad-16
excerpt: Understand the basics of function composition, a fundamental concept in functional programming.
listed: true
dateModified: 2023-12-29
journeyId: js/functional-programming... | unknown | unknown | ---
title: Function composition in JavaScript
shortTitle: Function composition
language: javascript
tags: [function]
cover: digital-nomad-16
excerpt: Understand the basics of function composition, a fundamental concept in functional programming.
listed: true
dateModified: 2023-12-29
journeyId: js/functional-programming... | ---
title: Function composition in JavaScript
shortTitle: Function composition
language: javascript
tags: [function]
cover: digital-nomad-16
excerpt: Understand the basics of function composition, a fundamental concept in functional programming.
listed: true
dateModified: 2023-12-29
journeyId: js/functional-programming... | code_snippets | ||
04d19016-6ab8-43eb-9f96-a41fde935d52 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-arity.md | unknown | 22ff72e4-f339-455b-9e20-7087d9f4bc07 | 1 | SemanticChunker@1.0.0 | 1c0a3855c5fbac1aef8eb73283d81da6794974eedbd4c52556dad09a17ea42b4 | [Getting the arity of a function]
## Getting the arity of a function
The arity of a function can be easily retrieved using `Function.prototype.length`.
```js
const arity = fn => fn.length;
arity(Math.sqrt); // 1
arity(Math.pow); // 2
arity((x, y, z) => x + y + z); // 3
arity((...args) => args); // 0
```
As you can... | unknown | unknown | [Getting the arity of a function]
## Getting the arity of a function
The arity of a function can be easily retrieved using `Function.prototype.length`.
```js
const arity = fn => fn.length;
arity(Math.sqrt); // 1
arity(Math.pow); // 2
arity((x, y, z) => x + y + z); // 3
arity((...args) => args); // 0
```
As you can... | [Getting the arity of a function]
## Getting the arity of a function
The arity of a function can be easily retrieved using `Function.prototype.length`.
```js
const arity = fn => fn.length;
arity(Math.sqrt); // 1
arity(Math.pow); // 2
arity((x, y, z) => x + y + z); // 3
arity((...args) => args); // 0
```
As you can... | code_snippets | ||
1e19f17a-3bc1-42fe-985d-8ca45915a08d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-arity.md | unknown | 22ff72e4-f339-455b-9e20-7087d9f4bc07 | 2 | SemanticChunker@1.0.0 | 58730bcb97fd8d1d7eac70863f3a6ba628a4a6e056aeffd2c4ea54398b736147 | [Getting the arity of a function > Creating a function with a fixed arity]
## Creating a function with a fixed arity
In some cases, we might want to limit the number of arguments a function can accept. This comes in handy for variadic functions, especially when combined with [currying](/js/s/curring). | unknown | unknown | [Getting the arity of a function > Creating a function with a fixed arity]
## Creating a function with a fixed arity
In some cases, we might want to limit the number of arguments a function can accept. This comes in handy for variadic functions, especially when combined with [currying](/js/s/curring). | [Getting the arity of a function > Creating a function with a fixed arity]
## Creating a function with a fixed arity
In some cases, we might want to limit the number of arguments a function can accept. This comes in handy for variadic functions, especially when combined with [currying](/js/s/curring). | code_snippets | ||
22dc8eee-fa07-497c-b473-3a763cf65132 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-arity.md | unknown | 22ff72e4-f339-455b-9e20-7087d9f4bc07 | 7 | SemanticChunker@1.0.0 | 425bf36c6c25f30ca69d02772c71953f3929acdacb699ce3bb0bed471a51f241 | [Getting the arity of a function > Converting array-accepting functions to variadic functions]
## Converting array-accepting functions to variadic functions
In some cases, it might be easier to convert a function that accepts an array of arguments into a variadic function. Or, perhaps, we might want to do the opposit... | unknown | unknown | [Getting the arity of a function > Converting array-accepting functions to variadic functions]
## Converting array-accepting functions to variadic functions
In some cases, it might be easier to convert a function that accepts an array of arguments into a variadic function. Or, perhaps, we might want to do the opposit... | [Getting the arity of a function > Converting array-accepting functions to variadic functions]
## Converting array-accepting functions to variadic functions
In some cases, it might be easier to convert a function that accepts an array of arguments into a variadic function. Or, perhaps, we might want to do the opposit... | code_snippets | ||
3193f01a-3f19-4cb4-9674-c7add0689218 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-arity.md | unknown | 22ff72e4-f339-455b-9e20-7087d9f4bc07 | 6 | SemanticChunker@1.0.0 | 9e6418618e423f48c45d451b99dcbd87f764b8aefe9eb5ad2aff6ff7493deef0 | [Creating a function with a fixed arity > N-ary function arity]
### N-ary function arity
In general, a **n-ary function** is a function that accepts **exactly `n` arguments**. Using `Array.prototype.slice()` and the spread operator (`...`), we can create a function that will call the provided function with the first ... | unknown | unknown | [Creating a function with a fixed arity > N-ary function arity]
### N-ary function arity
In general, a **n-ary function** is a function that accepts **exactly `n` arguments**. Using `Array.prototype.slice()` and the spread operator (`...`), we can create a function that will call the provided function with the first ... | [Creating a function with a fixed arity > N-ary function arity]
### N-ary function arity
In general, a **n-ary function** is a function that accepts **exactly `n` arguments**. Using `Array.prototype.slice()` and the spread operator (`...`), we can create a function that will call the provided function with the first ... | code_snippets | ||
61639294-026e-4fb5-ac77-22e1ca032c57 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-arity.md | unknown | 22ff72e4-f339-455b-9e20-7087d9f4bc07 | 5 | SemanticChunker@1.0.0 | e80a5a6512acf69a1594a436b3730ec1b7658389535e15cebe53e219b38ef988 | [Creating a function with a fixed arity > Binary function arity]
### Binary function arity
A **binary function** is a function that accepts **exactly two arguments**. Similarly to the unary function, we can create a binary function by calling the function with just the first two arguments provided.
```js
const binar... | unknown | unknown | [Creating a function with a fixed arity > Binary function arity]
### Binary function arity
A **binary function** is a function that accepts **exactly two arguments**. Similarly to the unary function, we can create a binary function by calling the function with just the first two arguments provided.
```js
const binar... | [Creating a function with a fixed arity > Binary function arity]
### Binary function arity
A **binary function** is a function that accepts **exactly two arguments**. Similarly to the unary function, we can create a binary function by calling the function with just the first two arguments provided.
```js
const binar... | code_snippets | ||
7d213be4-d5f7-46df-9ee2-8c085cab2e4e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-arity.md | unknown | 22ff72e4-f339-455b-9e20-7087d9f4bc07 | 0 | SemanticChunker@1.0.0 | b9be9c88ee003ee35d16af58545f030aa0fad87caa9ade4dff9719a9c083787b | ---
title: JavaScript function arity
shortTitle: Function arity
language: javascript
tags: [function]
cover: radio-monstera
excerpt: Function arity is a simple, yet useful concept in functional programming, especially when combined with currying.
listed: true
dateModified: 2023-12-29
journeyId: js/functional-programmin... | unknown | unknown | ---
title: JavaScript function arity
shortTitle: Function arity
language: javascript
tags: [function]
cover: radio-monstera
excerpt: Function arity is a simple, yet useful concept in functional programming, especially when combined with currying.
listed: true
dateModified: 2023-12-29
journeyId: js/functional-programmin... | ---
title: JavaScript function arity
shortTitle: Function arity
language: javascript
tags: [function]
cover: radio-monstera
excerpt: Function arity is a simple, yet useful concept in functional programming, especially when combined with currying.
listed: true
dateModified: 2023-12-29
journeyId: js/functional-programmin... | code_snippets | ||
807f137f-216f-4700-91c7-e01ada55b12a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-arity.md | unknown | 22ff72e4-f339-455b-9e20-7087d9f4bc07 | 4 | SemanticChunker@1.0.0 | bda51331c5fcbe375332a8ace6f8db4a7e75a7a20d8d6c16ff62d84cd73e98e3 | [Creating a function with a fixed arity > Unary function arity]
### Unary function arity
A **unary function** is a function that accepts **exactly one argument** and can be created by calling the function with just the first argument provided.
```js
const unary = fn => val => fn(val);
['6', '8', '10'].map(unary(Num... | unknown | unknown | [Creating a function with a fixed arity > Unary function arity]
### Unary function arity
A **unary function** is a function that accepts **exactly one argument** and can be created by calling the function with just the first argument provided.
```js
const unary = fn => val => fn(val);
['6', '8', '10'].map(unary(Num... | [Creating a function with a fixed arity > Unary function arity]
### Unary function arity
A **unary function** is a function that accepts **exactly one argument** and can be created by calling the function with just the first argument provided.
```js
const unary = fn => val => fn(val);
['6', '8', '10'].map(unary(Num... | code_snippets | ||
e654b688-55ca-498d-82fe-6def176d0467 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/function-arity.md | unknown | 22ff72e4-f339-455b-9e20-7087d9f4bc07 | 3 | SemanticChunker@1.0.0 | 15747cd57f954162632aeb1d3300744eeea3889e248c0deccc5c598e988910bf | [Creating a function with a fixed arity > Nullary function arity]
### Nullary function arity
A **nullary function** is a function that accepts **no arguments**. In that case, we can simply call the function without any arguments.
```js
const nullary = fn => () => fn();
nullary(Math.random)(); // 0.6019623086
``` | unknown | unknown | [Creating a function with a fixed arity > Nullary function arity]
### Nullary function arity
A **nullary function** is a function that accepts **no arguments**. In that case, we can simply call the function without any arguments.
```js
const nullary = fn => () => fn();
nullary(Math.random)(); // 0.6019623086
``` | [Creating a function with a fixed arity > Nullary function arity]
### Nullary function arity
A **nullary function** is a function that accepts **no arguments**. In that case, we can simply call the function without any arguments.
```js
const nullary = fn => () => fn();
nullary(Math.random)(); // 0.6019623086
``` | code_snippets | ||
43e56f67-797f-404b-b437-5e25e5016da3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/form-to-object.md | unknown | 083d3ecb-ca39-48d2-b471-1b45b1e1b291 | 1 | SemanticChunker@1.0.0 | d2d70fd1f37a6ca69de78a78709c4c7e9fa206fb1ba3ac8b29a219d75b06557b | [Convert form data to an object]
## Convert form data to an object
The `FormData` interface provides a way to easily construct a set of **key/value pairs** representing form fields and their values, which can then be easily converted to an object. Using the `FormData()` constructor with a reference to the **form elem... | unknown | unknown | [Convert form data to an object]
## Convert form data to an object
The `FormData` interface provides a way to easily construct a set of **key/value pairs** representing form fields and their values, which can then be easily converted to an object. Using the `FormData()` constructor with a reference to the **form elem... | [Convert form data to an object]
## Convert form data to an object
The `FormData` interface provides a way to easily construct a set of **key/value pairs** representing form fields and their values, which can then be easily converted to an object. Using the `FormData()` constructor with a reference to the **form elem... | code_snippets | ||
493c47dd-3ddb-4876-ad30-d8c678a41f93 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/form-to-object.md | unknown | 083d3ecb-ca39-48d2-b471-1b45b1e1b291 | 0 | SemanticChunker@1.0.0 | 5345d3c6d7d85d1b92362c776ff43d08afb314f766024b21aa342975c0236484 | ---
title: How can I convert the data from an HTML form to a JavaScript object?
shortTitle: Form to object
language: javascript
tags: [browser,object]
cover: down-the-stream
excerpt: Convert the data from an HTML form into a JavaScript object or serialize it into a query string.
listed: true
dateModified: 2024-01-21
--... | unknown | unknown | ---
title: How can I convert the data from an HTML form to a JavaScript object?
shortTitle: Form to object
language: javascript
tags: [browser,object]
cover: down-the-stream
excerpt: Convert the data from an HTML form into a JavaScript object or serialize it into a query string.
listed: true
dateModified: 2024-01-21
--... | ---
title: How can I convert the data from an HTML form to a JavaScript object?
shortTitle: Form to object
language: javascript
tags: [browser,object]
cover: down-the-stream
excerpt: Convert the data from an HTML form into a JavaScript object or serialize it into a query string.
listed: true
dateModified: 2024-01-21
--... | code_snippets | ||
6ada3aec-bdc2-419e-8870-7df7635406d7 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/form-to-object.md | unknown | 083d3ecb-ca39-48d2-b471-1b45b1e1b291 | 2 | SemanticChunker@1.0.0 | d4b5446c1e0a194ca122a0028963b26ffac646c6acc3f2407968acc5040e9380 | [Convert form data to an object > Serialize form data to a query string]
## Serialize form data to a query string
If, instead of an object, you need to **serialize the data** from a form into a query string, you need to make a few adjustments to the previous code snippet.
After creating a `FormData` object, you can ... | unknown | unknown | [Convert form data to an object > Serialize form data to a query string]
## Serialize form data to a query string
If, instead of an object, you need to **serialize the data** from a form into a query string, you need to make a few adjustments to the previous code snippet.
After creating a `FormData` object, you can ... | [Convert form data to an object > Serialize form data to a query string]
## Serialize form data to a query string
If, instead of an object, you need to **serialize the data** from a form into a query string, you need to make a few adjustments to the previous code snippet.
After creating a `FormData` object, you can ... | code_snippets | ||
2a78018e-6545-4c45-9a8e-d0f8b28e148f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/fullscreen.md | unknown | 9362a9d5-3fb9-4ff4-92e2-2a85da5fbe69 | 1 | SemanticChunker@1.0.0 | 4d9dc1ca583d122f4a23779629c70b0b7ebcc7bff23c11a1c22d2fa4e58fcd83 | ```js
const toggleFullscreen = (mode = true, el = 'body', ui = 'auto') =>
mode
? document.querySelector(el).requestFullscreen({ navigationUI: ui })
: document.exitFullscreen();
toggleFullscreen();
// Opens `body` in fullscreen mode
toggleFullscreen(false);
// Exits fullscreen mode
toggleFullscreen(true, '#myElement... | unknown | unknown | ```js
const toggleFullscreen = (mode = true, el = 'body', ui = 'auto') =>
mode
? document.querySelector(el).requestFullscreen({ navigationUI: ui })
: document.exitFullscreen();
toggleFullscreen();
// Opens `body` in fullscreen mode
toggleFullscreen(false);
// Exits fullscreen mode
toggleFullscreen(true, '#myElement... | ```js
const toggleFullscreen = (mode = true, el = 'body', ui = 'auto') =>
mode
? document.querySelector(el).requestFullscreen({ navigationUI: ui })
: document.exitFullscreen();
toggleFullscreen();
// Opens `body` in fullscreen mode
toggleFullscreen(false);
// Exits fullscreen mode
toggleFullscreen(true, '#myElement... | code_snippets | ||
52ce2401-d35a-4bc5-af25-2e7b8921ff36 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/fullscreen.md | unknown | 9362a9d5-3fb9-4ff4-92e2-2a85da5fbe69 | 0 | SemanticChunker@1.0.0 | 6cb7ce33682915336271e5d7b6065aa20bef9bfb06dd829f1a6e5a1737257005 | ---
title: Toggle fullscreen mode for an element using JavaScript
shortTitle: Fullscreen mode
language: javascript
tags: [browser]
cover: cloudy-mountaintop-2
excerpt: Did you know you can use JavaScript to toggle fullscreen mode for an element on a webpage? Let's learn how!
listed: true
dateModified: 2024-05-23
---
<... | unknown | unknown | ---
title: Toggle fullscreen mode for an element using JavaScript
shortTitle: Fullscreen mode
language: javascript
tags: [browser]
cover: cloudy-mountaintop-2
excerpt: Did you know you can use JavaScript to toggle fullscreen mode for an element on a webpage? Let's learn how!
listed: true
dateModified: 2024-05-23
---
<... | ---
title: Toggle fullscreen mode for an element using JavaScript
shortTitle: Fullscreen mode
language: javascript
tags: [browser]
cover: cloudy-mountaintop-2
excerpt: Did you know you can use JavaScript to toggle fullscreen mode for an element on a webpage? Let's learn how!
listed: true
dateModified: 2024-05-23
---
<... | code_snippets | ||
68ffef42-afb6-4bce-921b-92f4028ee402 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/for-loop-early-break.md | unknown | a4cfbdf9-4ded-4aea-a929-0507455c4d1f | 0 | SemanticChunker@1.0.0 | 21522f84b115c5b72141ae0891a54e3203345a77ecc1cfa2be3b6e38c8870317 | ---
title: Use JavaScript for loops if you need to break out early
shortTitle: For loops for early breaking
language: javascript
tags: [array,loop]
cover: armchair
excerpt: Iteration in JavaScript can be done a handfuld of ways, most often using array methods, but sometimes a `for` loop is the best option.
listed: true... | unknown | unknown | ---
title: Use JavaScript for loops if you need to break out early
shortTitle: For loops for early breaking
language: javascript
tags: [array,loop]
cover: armchair
excerpt: Iteration in JavaScript can be done a handfuld of ways, most often using array methods, but sometimes a `for` loop is the best option.
listed: true... | ---
title: Use JavaScript for loops if you need to break out early
shortTitle: For loops for early breaking
language: javascript
tags: [array,loop]
cover: armchair
excerpt: Iteration in JavaScript can be done a handfuld of ways, most often using array methods, but sometimes a `for` loop is the best option.
listed: true... | code_snippets | ||
185f8944-6463-4e14-8ea2-5f65f507a942 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/formatting-day-hour-ranges.md | unknown | d74ce636-7b6f-4d7f-8698-417ecb7c27e6 | 4 | SemanticChunker@1.0.0 | cd11a5e27661adc779c968819725f4d7b5973134a29188f01f30c57bcbdab853 | [Definition > Solution]
```js
const weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
const formatDayRanges = (data) =>
weekdays.reduce((acc, day) => {
const dayData = data.find((d) => d.day === day);
const hours = dayData ? `${dayData.from} - ${dayData.to}` : 'Closed';
... | unknown | unknown | [Definition > Solution]
```js
const weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
const formatDayRanges = (data) =>
weekdays.reduce((acc, day) => {
const dayData = data.find((d) => d.day === day);
const hours = dayData ? `${dayData.from} - ${dayData.to}` : 'Closed';
... | [Definition > Solution]
```js
const weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
const formatDayRanges = (data) =>
weekdays.reduce((acc, day) => {
const dayData = data.find((d) => d.day === day);
const hours = dayData ? `${dayData.from} - ${dayData.to}` : 'Closed';
... | code_snippets | ||
1c849eab-1723-4a97-982b-c5b97e080a6a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/formatting-day-hour-ranges.md | unknown | d74ce636-7b6f-4d7f-8698-417ecb7c27e6 | 1 | SemanticChunker@1.0.0 | 1943d2a002708249e39eeb23937f3df5301fc03e2b7a7c80636f0b53dd87df6d | [Definition]
## Definition
Instead of boring you with all the details, I'll get straight to the specifics. Given an **array of objects**, containing **day names** and respective **working hour ranges**, I needed to format this data into an **array of human-readable strings**.
Let's look at an example to make things ... | unknown | unknown | [Definition]
## Definition
Instead of boring you with all the details, I'll get straight to the specifics. Given an **array of objects**, containing **day names** and respective **working hour ranges**, I needed to format this data into an **array of human-readable strings**.
Let's look at an example to make things ... | [Definition]
## Definition
Instead of boring you with all the details, I'll get straight to the specifics. Given an **array of objects**, containing **day names** and respective **working hour ranges**, I needed to format this data into an **array of human-readable strings**.
Let's look at an example to make things ... | code_snippets | ||
73178c93-6779-486b-ac04-e5e35381bfc5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/formatting-day-hour-ranges.md | unknown | d74ce636-7b6f-4d7f-8698-417ecb7c27e6 | 5 | SemanticChunker@1.0.0 | 285a2ac434e15b4d52d60d93d43768594c2a7f6618a4306bb52a684f22df75ea | [Definition > Solution]
if (acc.length && acc[acc.length - 1].hours === hours) {
acc[acc.length - 1].days.push(day);
} else {
acc.push({ days: [day], hours });
}
return acc;
}, [])
.map(({ days, hours }) => {
if (days.length === 1) return `${days[0]}: ${hours}`;
if (days.length === 7) return `Everyday: ${hou... | unknown | unknown | [Definition > Solution]
if (acc.length && acc[acc.length - 1].hours === hours) {
acc[acc.length - 1].days.push(day);
} else {
acc.push({ days: [day], hours });
}
return acc;
}, [])
.map(({ days, hours }) => {
if (days.length === 1) return `${days[0]}: ${hours}`;
if (days.length === 7) return `Everyday: ${hou... | [Definition > Solution]
if (acc.length && acc[acc.length - 1].hours === hours) {
acc[acc.length - 1].days.push(day);
} else {
acc.push({ days: [day], hours });
}
return acc;
}, [])
.map(({ days, hours }) => {
if (days.length === 1) return `${days[0]}: ${hours}`;
if (days.length === 7) return `Everyday: ${hou... | code_snippets | ||
7dccd120-dab4-4368-bff7-c04c5da44d19 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/formatting-day-hour-ranges.md | unknown | d74ce636-7b6f-4d7f-8698-417ecb7c27e6 | 2 | SemanticChunker@1.0.0 | 70b6bac728eb7831a355305f30df6fea6076f5fba652a10ff10a0356a25a8057 | [Definition > Breakdown]
## Breakdown
Before even attempting to implement a solution, it's a good idea to **break down the problem**. In my head, this translates to the following subproblems:
1. **Group the days** with consecutive working hours.
2. **Format the grouped days** into human-readable strings.
3. **Add th... | unknown | unknown | [Definition > Breakdown]
## Breakdown
Before even attempting to implement a solution, it's a good idea to **break down the problem**. In my head, this translates to the following subproblems:
1. **Group the days** with consecutive working hours.
2. **Format the grouped days** into human-readable strings.
3. **Add th... | [Definition > Breakdown]
## Breakdown
Before even attempting to implement a solution, it's a good idea to **break down the problem**. In my head, this translates to the following subproblems:
1. **Group the days** with consecutive working hours.
2. **Format the grouped days** into human-readable strings.
3. **Add th... | code_snippets | ||
a35f7188-3621-407a-b9d1-95b6eb2f1b46 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/formatting-day-hour-ranges.md | unknown | d74ce636-7b6f-4d7f-8698-417ecb7c27e6 | 6 | SemanticChunker@1.0.0 | 21c10618e5ad7f6b6f40d70b9d9e19a7faf49534971a862eac2c410c672d187d | [Definition > Solution]
```
Notice that we're using a **second loop** over the first grouped result in the form of `Array.prototype.map()`. This can be avoided, but I found it to be more readable and easier to understand. Moreover, the performance impact is negligible.
Another point of interest is the use of `Array.... | unknown | unknown | [Definition > Solution]
```
Notice that we're using a **second loop** over the first grouped result in the form of `Array.prototype.map()`. This can be avoided, but I found it to be more readable and easier to understand. Moreover, the performance impact is negligible.
Another point of interest is the use of `Array.... | [Definition > Solution]
```
Notice that we're using a **second loop** over the first grouped result in the form of `Array.prototype.map()`. This can be avoided, but I found it to be more readable and easier to understand. Moreover, the performance impact is negligible.
Another point of interest is the use of `Array.... | code_snippets | ||
c9f6c744-7146-4945-992d-0cd15aed33a4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/formatting-day-hour-ranges.md | unknown | d74ce636-7b6f-4d7f-8698-417ecb7c27e6 | 3 | SemanticChunker@1.0.0 | d1164cb1e13100cad6128f6b6b3d41753483f91fe5f231e1767e299f89c1735a | [Definition > Solution]
## Solution
Having broken down the problem, the solution can be approached in smaller steps, incrementally building up the final result. Let's start with the first subproblem.
This is the most algorithmic part of the problem and the one that may require the most thought to get right. I was va... | unknown | unknown | [Definition > Solution]
## Solution
Having broken down the problem, the solution can be approached in smaller steps, incrementally building up the final result. Let's start with the first subproblem.
This is the most algorithmic part of the problem and the one that may require the most thought to get right. I was va... | [Definition > Solution]
## Solution
Having broken down the problem, the solution can be approached in smaller steps, incrementally building up the final result. Let's start with the first subproblem.
This is the most algorithmic part of the problem and the one that may require the most thought to get right. I was va... | code_snippets | ||
f52c09b4-0773-4f0b-8ef8-27edcffa48ee | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/formatting-day-hour-ranges.md | unknown | d74ce636-7b6f-4d7f-8698-417ecb7c27e6 | 0 | SemanticChunker@1.0.0 | a19741721147da95c6e480207dc816f32b22b6c0c84197d58a2aeb35b2ffb894 | ---
title: Formatting day and hour ranges with JavaScript
shortTitle: Day and hour range formatting
language: javascript
tags: [date]
cover: tram-car-2
excerpt: I recently came across a fairly interesting algorithmic problem when formatting day and hour ranges. Here's my take on the solution.
listed: true
dateModified:... | unknown | unknown | ---
title: Formatting day and hour ranges with JavaScript
shortTitle: Day and hour range formatting
language: javascript
tags: [date]
cover: tram-car-2
excerpt: I recently came across a fairly interesting algorithmic problem when formatting day and hour ranges. Here's my take on the solution.
listed: true
dateModified:... | ---
title: Formatting day and hour ranges with JavaScript
shortTitle: Day and hour range formatting
language: javascript
tags: [date]
cover: tram-car-2
excerpt: I recently came across a fairly interesting algorithmic problem when formatting day and hour ranges. Here's my take on the solution.
listed: true
dateModified:... | code_snippets | ||
462e789a-e132-47f6-ae09-5c1da51b4223 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/for-in-for-of-foreach.md | unknown | 77a5e29b-88b5-45e1-a111-a47f3dd4adda | 0 | SemanticChunker@1.0.0 | 8563ffd73adec903c1baa2406f25c5d4a2687e86bb4b12ff4f0a43de4a66b707 | ---
title: What is the difference between JavaScript's for...in, for...of and forEach?
shortTitle: JavaScript iteration methods comparison
language: javascript
tags: [array,object,iterator]
cover: lake-loop
excerpt: Learn the differences between the three most commonly used iteration methods in JavaScript, that often c... | unknown | unknown | ---
title: What is the difference between JavaScript's for...in, for...of and forEach?
shortTitle: JavaScript iteration methods comparison
language: javascript
tags: [array,object,iterator]
cover: lake-loop
excerpt: Learn the differences between the three most commonly used iteration methods in JavaScript, that often c... | ---
title: What is the difference between JavaScript's for...in, for...of and forEach?
shortTitle: JavaScript iteration methods comparison
language: javascript
tags: [array,object,iterator]
cover: lake-loop
excerpt: Learn the differences between the three most commonly used iteration methods in JavaScript, that often c... | code_snippets | ||
481e550c-db09-4679-80fe-cbd88c8ff43d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/for-in-for-of-foreach.md | unknown | 77a5e29b-88b5-45e1-a111-a47f3dd4adda | 2 | SemanticChunker@1.0.0 | 96de0a29fc982c0e4d8e4ac11190bb3587a74c26308bb13176fa86bbcba828f3 | [`for...in` > `for...of`]
## `for...of`
`for...of` is used to iterate over iterable objects, iterating **over their values instead of their properties**. This iteration statement can be used with arrays, strings, `Map` or `Set` objects, but not with plain objects.
```js
for (let val of ['a', 'b', 'c'])
console.log(... | unknown | unknown | [`for...in` > `for...of`]
## `for...of`
`for...of` is used to iterate over iterable objects, iterating **over their values instead of their properties**. This iteration statement can be used with arrays, strings, `Map` or `Set` objects, but not with plain objects.
```js
for (let val of ['a', 'b', 'c'])
console.log(... | [`for...in` > `for...of`]
## `for...of`
`for...of` is used to iterate over iterable objects, iterating **over their values instead of their properties**. This iteration statement can be used with arrays, strings, `Map` or `Set` objects, but not with plain objects.
```js
for (let val of ['a', 'b', 'c'])
console.log(... | code_snippets | ||
d68e3dcc-3bc1-41b9-b2e3-6d194471983d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/for-in-for-of-foreach.md | unknown | 77a5e29b-88b5-45e1-a111-a47f3dd4adda | 1 | SemanticChunker@1.0.0 | b731f91b09b07a8b398cb29762e1db05788904395691414602ba77092023c239 | [`for...in`]
## `for...in`
`for...in` is used to iterate over **all enumerable properties of an object**, including inherited enumerable properties. This iteration statement can be used with arrays, strings or plain objects, but not with `Map` or `Set` objects.
```js
for (let prop in ['a', 'b', 'c'])
console.log(pr... | unknown | unknown | [`for...in`]
## `for...in`
`for...in` is used to iterate over **all enumerable properties of an object**, including inherited enumerable properties. This iteration statement can be used with arrays, strings or plain objects, but not with `Map` or `Set` objects.
```js
for (let prop in ['a', 'b', 'c'])
console.log(pr... | [`for...in`]
## `for...in`
`for...in` is used to iterate over **all enumerable properties of an object**, including inherited enumerable properties. This iteration statement can be used with arrays, strings or plain objects, but not with `Map` or `Set` objects.
```js
for (let prop in ['a', 'b', 'c'])
console.log(pr... | code_snippets | ||
ffa1e1aa-d541-4caa-b983-0b4b60442fbc | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/for-in-for-of-foreach.md | unknown | 77a5e29b-88b5-45e1-a111-a47f3dd4adda | 3 | SemanticChunker@1.0.0 | 6adb4154e9c009dc3db14b6149be418ae2490d871b802ac362402cbd54ab59e5 | [`for...in` > `Array.prototype.forEach()`]
## `Array.prototype.forEach()`
Finally, `forEach()` is a method of the `Array` prototype, which allows you to iterate **over the elements of an array**. While `Array.prototype.forEach()` only iterates over arrays, it can access both the value and the index of each element wh... | unknown | unknown | [`for...in` > `Array.prototype.forEach()`]
## `Array.prototype.forEach()`
Finally, `forEach()` is a method of the `Array` prototype, which allows you to iterate **over the elements of an array**. While `Array.prototype.forEach()` only iterates over arrays, it can access both the value and the index of each element wh... | [`for...in` > `Array.prototype.forEach()`]
## `Array.prototype.forEach()`
Finally, `forEach()` is a method of the `Array` prototype, which allows you to iterate **over the elements of an array**. While `Array.prototype.forEach()` only iterates over arrays, it can access both the value and the index of each element wh... | code_snippets | ||
07de6df7-9198-4914-a628-621c6ed9c860 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-ancestors-parents-siblings-children.md | unknown | 02dd5868-0d3d-4d9c-85ae-a694d88625b0 | 7 | SemanticChunker@1.0.0 | 721b7da16dab03b696d596c2ecb883b4bfc57cb24aebcd58ae5ae0000306e442 | [Matching related nodes > Get parents until element matches selector]
### Get parents until element matches selector
To find all the ancestors of an element up until the element matched by the specified selector, we can use a `while` loop and `Node.parentNode` to **move up the ancestor tree** of the element. We can t... | unknown | unknown | [Matching related nodes > Get parents until element matches selector]
### Get parents until element matches selector
To find all the ancestors of an element up until the element matched by the specified selector, we can use a `while` loop and `Node.parentNode` to **move up the ancestor tree** of the element. We can t... | [Matching related nodes > Get parents until element matches selector]
### Get parents until element matches selector
To find all the ancestors of an element up until the element matched by the specified selector, we can use a `while` loop and `Node.parentNode` to **move up the ancestor tree** of the element. We can t... | code_snippets | ||
0934189d-c4b3-4c72-9b36-9946ba801038 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-ancestors-parents-siblings-children.md | unknown | 02dd5868-0d3d-4d9c-85ae-a694d88625b0 | 3 | SemanticChunker@1.0.0 | d3d52dc1c3409dae7400b5fc3ed12fad02794f337ce26895b70be76c05e62231 | [Get an element's children > Get an element's ancestors]
## Get an element's ancestors
To get all the **ancestors** of an element, we can use a `while` loop and the `Node.parentNode` property to **move up the ancestor tree** of the element. We can then use `Array.prototype.unshift()` to add each new ancestor to the s... | unknown | unknown | [Get an element's children > Get an element's ancestors]
## Get an element's ancestors
To get all the **ancestors** of an element, we can use a `while` loop and the `Node.parentNode` property to **move up the ancestor tree** of the element. We can then use `Array.prototype.unshift()` to add each new ancestor to the s... | [Get an element's children > Get an element's ancestors]
## Get an element's ancestors
To get all the **ancestors** of an element, we can use a `while` loop and the `Node.parentNode` property to **move up the ancestor tree** of the element. We can then use `Array.prototype.unshift()` to add each new ancestor to the s... | code_snippets | ||
8d8cfb58-30a5-4899-9692-8030eeaa3d67 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-ancestors-parents-siblings-children.md | unknown | 02dd5868-0d3d-4d9c-85ae-a694d88625b0 | 5 | SemanticChunker@1.0.0 | fc8f086b808b0c6d4f1a9e1042b394021fcb62cca758010e72b4414fc250b2c7 | [Matching related nodes > Check if an element contains another element]
### Check if an element contains another element
To check if an element contains another element, we can simply use the `Node.contains()` method.
```js
const elementContains = (parent, child) =>
parent !== child && parent.contains(child);
elem... | unknown | unknown | [Matching related nodes > Check if an element contains another element]
### Check if an element contains another element
To check if an element contains another element, we can simply use the `Node.contains()` method.
```js
const elementContains = (parent, child) =>
parent !== child && parent.contains(child);
elem... | [Matching related nodes > Check if an element contains another element]
### Check if an element contains another element
To check if an element contains another element, we can simply use the `Node.contains()` method.
```js
const elementContains = (parent, child) =>
parent !== child && parent.contains(child);
elem... | code_snippets | ||
9f02a891-af2b-4ee7-92b7-3b650e5f04d6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-ancestors-parents-siblings-children.md | unknown | 02dd5868-0d3d-4d9c-85ae-a694d88625b0 | 6 | SemanticChunker@1.0.0 | cdeff4d5aa867e2c663ec3fd17fb72ee7ebc4d42d7de2550758d6a74254d26de | [Matching related nodes > Find closest matching node]
### Find closest matching node
Finding the closest matching node starting at the given `node` is often useful for event handling. We can use a `for` loop and `Node.parentNode` to **traverse the node tree upwards** from the given `node`. We then use `Element.matche... | unknown | unknown | [Matching related nodes > Find closest matching node]
### Find closest matching node
Finding the closest matching node starting at the given `node` is often useful for event handling. We can use a `for` loop and `Node.parentNode` to **traverse the node tree upwards** from the given `node`. We then use `Element.matche... | [Matching related nodes > Find closest matching node]
### Find closest matching node
Finding the closest matching node starting at the given `node` is often useful for event handling. We can use a `for` loop and `Node.parentNode` to **traverse the node tree upwards** from the given `node`. We then use `Element.matche... | code_snippets | ||
b220d286-05b9-4c42-a192-0fbb12d6cdf7 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-ancestors-parents-siblings-children.md | unknown | 02dd5868-0d3d-4d9c-85ae-a694d88625b0 | 4 | SemanticChunker@1.0.0 | 7434dc903298099e5ee1bd22d4b7b1a8018c8245e7b2986ba1247e8b91f8a54d | [Get an element's children > Matching related nodes]
## Matching related nodes
Building on top of the previous examples, we can create functions to **match related nodes** based on a given condition. For example, we can find all the ancestors of an element up until the element matched by a specified selector, or find... | unknown | unknown | [Get an element's children > Matching related nodes]
## Matching related nodes
Building on top of the previous examples, we can create functions to **match related nodes** based on a given condition. For example, we can find all the ancestors of an element up until the element matched by a specified selector, or find... | [Get an element's children > Matching related nodes]
## Matching related nodes
Building on top of the previous examples, we can create functions to **match related nodes** based on a given condition. For example, we can find all the ancestors of an element up until the element matched by a specified selector, or find... | code_snippets | ||
b718f2fb-8da6-447e-a0e5-833cd289b362 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-ancestors-parents-siblings-children.md | unknown | 02dd5868-0d3d-4d9c-85ae-a694d88625b0 | 1 | SemanticChunker@1.0.0 | a41f490001bfd5842c84ece19f157920178b074e2e9ff670e4667a934e47f26e | [Get an element's children]
## Get an element's children
Oddly enough, there are two ways to get an element's children: `Node.childNodes` and `Node.children`. The difference between the two is that `Node.childNodes` returns **all child nodes**, including text nodes, while `Node.children` returns **only element nodes*... | unknown | unknown | [Get an element's children]
## Get an element's children
Oddly enough, there are two ways to get an element's children: `Node.childNodes` and `Node.children`. The difference between the two is that `Node.childNodes` returns **all child nodes**, including text nodes, while `Node.children` returns **only element nodes*... | [Get an element's children]
## Get an element's children
Oddly enough, there are two ways to get an element's children: `Node.childNodes` and `Node.children`. The difference between the two is that `Node.childNodes` returns **all child nodes**, including text nodes, while `Node.children` returns **only element nodes*... | code_snippets | ||
bd422230-fb97-489c-b313-e6b051312cd5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-ancestors-parents-siblings-children.md | unknown | 02dd5868-0d3d-4d9c-85ae-a694d88625b0 | 2 | SemanticChunker@1.0.0 | 3de7390138f3a854b2905a2ebeb4621dfe87e403af6bedffc11017a75a241137 | [Get an element's children > Get an element's siblings]
## Get an element's siblings
To get an element's **siblings**, we can use the `Node.parentNode` property to access the parent node and then use `Node.childNodes` to get all the children of the parent.
We can then convert the `NodeList` to an array using the spr... | unknown | unknown | [Get an element's children > Get an element's siblings]
## Get an element's siblings
To get an element's **siblings**, we can use the `Node.parentNode` property to access the parent node and then use `Node.childNodes` to get all the children of the parent.
We can then convert the `NodeList` to an array using the spr... | [Get an element's children > Get an element's siblings]
## Get an element's siblings
To get an element's **siblings**, we can use the `Node.parentNode` property to access the parent node and then use `Node.childNodes` to get all the children of the parent.
We can then convert the `NodeList` to an array using the spr... | code_snippets | ||
d91103fe-f490-41c5-b7ad-a7c96bf57f7e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-ancestors-parents-siblings-children.md | unknown | 02dd5868-0d3d-4d9c-85ae-a694d88625b0 | 0 | SemanticChunker@1.0.0 | 6e570d51c7ae3779c1dc60151ccf177c486f96d190b090345c91e0d661b872f8 | ---
title: How can I get all ancestors, parents, siblings, and children of an element?
shortTitle: Get element ancestors, parents, siblings, and children
language: javascript
tags: [browser]
cover: flowering-hills
excerpt: Learn how to traverse the DOM and find all elements related to a given element.
listed: true
date... | unknown | unknown | ---
title: How can I get all ancestors, parents, siblings, and children of an element?
shortTitle: Get element ancestors, parents, siblings, and children
language: javascript
tags: [browser]
cover: flowering-hills
excerpt: Learn how to traverse the DOM and find all elements related to a given element.
listed: true
date... | ---
title: How can I get all ancestors, parents, siblings, and children of an element?
shortTitle: Get element ancestors, parents, siblings, and children
language: javascript
tags: [browser]
cover: flowering-hills
excerpt: Learn how to traverse the DOM and find all elements related to a given element.
listed: true
date... | code_snippets | ||
56574c10-0eb8-4c86-a08f-567b6308633f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-images.md | unknown | 39c565c8-444a-4625-a809-22866a750a99 | 1 | SemanticChunker@1.0.0 | b5975ce68fbceee2f9571ef01966d51dc7d36e1042516f61495fe2ecd2aad835 | ```js
const getImages = (el, includeDuplicates = false) => {
const images = [...el.getElementsByTagName('img')].map(img =>
img.getAttribute('src')
);
return includeDuplicates ? images : [...new Set(images)];
};
getImages(document, true);
// ['image1.jpg', 'image2.png', 'image1.png', '...']
getImages(document, fals... | unknown | unknown | ```js
const getImages = (el, includeDuplicates = false) => {
const images = [...el.getElementsByTagName('img')].map(img =>
img.getAttribute('src')
);
return includeDuplicates ? images : [...new Set(images)];
};
getImages(document, true);
// ['image1.jpg', 'image2.png', 'image1.png', '...']
getImages(document, fals... | ```js
const getImages = (el, includeDuplicates = false) => {
const images = [...el.getElementsByTagName('img')].map(img =>
img.getAttribute('src')
);
return includeDuplicates ? images : [...new Set(images)];
};
getImages(document, true);
// ['image1.jpg', 'image2.png', 'image1.png', '...']
getImages(document, fals... | code_snippets | ||
bc21a183-f507-4f4e-b040-009f6c218151 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-images.md | unknown | 39c565c8-444a-4625-a809-22866a750a99 | 0 | SemanticChunker@1.0.0 | ccf2c2b68e85e5ecceb7189d318ac9f8fe16b4752ee5dd64eb03cd0cf55a0893 | ---
title: Use JavaScript to find all the images in an element
shortTitle: Get all images in element
language: javascript
tags: [browser]
cover: portal-timelapse
excerpt: Use simple DOM queries to find all the images contained within an element.
listed: true
dateModified: 2024-05-31
---
JavaScript is extremely powerfu... | unknown | unknown | ---
title: Use JavaScript to find all the images in an element
shortTitle: Get all images in element
language: javascript
tags: [browser]
cover: portal-timelapse
excerpt: Use simple DOM queries to find all the images contained within an element.
listed: true
dateModified: 2024-05-31
---
JavaScript is extremely powerfu... | ---
title: Use JavaScript to find all the images in an element
shortTitle: Get all images in element
language: javascript
tags: [browser]
cover: portal-timelapse
excerpt: Use simple DOM queries to find all the images contained within an element.
listed: true
dateModified: 2024-05-31
---
JavaScript is extremely powerfu... | code_snippets | ||
1da8ff3f-d854-428e-87c0-a01fefa6dbbe | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-base-url-or-url-params.md | unknown | 2b759129-95f8-4120-b04d-ac4eb10fbb89 | 0 | SemanticChunker@1.0.0 | bf02340c32f62adfcf41f27bfe0314f14bc46c8709d2648847984d4103b74f02 | ---
title: How do I use JavaScript to get the base URL or the URL parameters?
shortTitle: Get base URL or URL parameters
language: javascript
tags: [string,browser,regexp]
cover: blue-lake
excerpt: Master URL handling by learning how to get the base URL and the URL parameters as an object in JavaScript.
listed: true
da... | unknown | unknown | ---
title: How do I use JavaScript to get the base URL or the URL parameters?
shortTitle: Get base URL or URL parameters
language: javascript
tags: [string,browser,regexp]
cover: blue-lake
excerpt: Master URL handling by learning how to get the base URL and the URL parameters as an object in JavaScript.
listed: true
da... | ---
title: How do I use JavaScript to get the base URL or the URL parameters?
shortTitle: Get base URL or URL parameters
language: javascript
tags: [string,browser,regexp]
cover: blue-lake
excerpt: Master URL handling by learning how to get the base URL and the URL parameters as an object in JavaScript.
listed: true
da... | code_snippets | ||
53ddf8cd-ce1f-46e1-89e5-3898585c3abc | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-base-url-or-url-params.md | unknown | 2b759129-95f8-4120-b04d-ac4eb10fbb89 | 2 | SemanticChunker@1.0.0 | 2238a80bffe07fbd3468ca68632f16d9db6a649d4c7e97bc56dcc741dfb51d37 | [Get base URL > Get URL parameters object]
## Get URL parameters object
Similarly, you can extract the **URL parameters** as an **object** by using a **regular expression** and `String.prototype.match()` to match all key-value pairs. Then, you can use `Array.prototype.reduce()` to map and combine them into a single o... | unknown | unknown | [Get base URL > Get URL parameters object]
## Get URL parameters object
Similarly, you can extract the **URL parameters** as an **object** by using a **regular expression** and `String.prototype.match()` to match all key-value pairs. Then, you can use `Array.prototype.reduce()` to map and combine them into a single o... | [Get base URL > Get URL parameters object]
## Get URL parameters object
Similarly, you can extract the **URL parameters** as an **object** by using a **regular expression** and `String.prototype.match()` to match all key-value pairs. Then, you can use `Array.prototype.reduce()` to map and combine them into a single o... | code_snippets | ||
ddf50e40-a35c-4812-87d6-77142de25aa0 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-base-url-or-url-params.md | unknown | 2b759129-95f8-4120-b04d-ac4eb10fbb89 | 1 | SemanticChunker@1.0.0 | c2fb2281caa11d4e61a891cbc819bfb60745037c65a4a895d68b134a3532bcd6 | [Get base URL]
## Get base URL
The **base URL** is the part of the URL that comes **before any parameters or fragment identifiers**. To get the base URL, you can use a **regular expression** to remove everything after either `'?'` or `'#'`, with the help of `String.prototype.replace()`.
```js
const getBaseURL = url ... | unknown | unknown | [Get base URL]
## Get base URL
The **base URL** is the part of the URL that comes **before any parameters or fragment identifiers**. To get the base URL, you can use a **regular expression** to remove everything after either `'?'` or `'#'`, with the help of `String.prototype.replace()`.
```js
const getBaseURL = url ... | [Get base URL]
## Get base URL
The **base URL** is the part of the URL that comes **before any parameters or fragment identifiers**. To get the base URL, you can use a **regular expression** to remove everything after either `'?'` or `'#'`, with the help of `String.prototype.replace()`.
```js
const getBaseURL = url ... | code_snippets | ||
8d89d712-1d0d-43db-ab55-03eb7f320d30 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-scroll-position.md | unknown | 3e976d4f-2dcc-483e-aa9e-547c183277d6 | 0 | SemanticChunker@1.0.0 | 5576cdc85f92ca76375b03e25ce4cc0fa3bfef7b987ee61186a17d392ead4109 | ---
title: Get the scroll position of the current page using JavaScript
shortTitle: Get scroll position
language: javascript
tags: [browser]
cover: tranquil-lake
excerpt: Calculate the coordinates of the current scroll position in the browser window using JavaScript.
listed: true
dateModified: 2024-02-25
---
JavaScrip... | unknown | unknown | ---
title: Get the scroll position of the current page using JavaScript
shortTitle: Get scroll position
language: javascript
tags: [browser]
cover: tranquil-lake
excerpt: Calculate the coordinates of the current scroll position in the browser window using JavaScript.
listed: true
dateModified: 2024-02-25
---
JavaScrip... | ---
title: Get the scroll position of the current page using JavaScript
shortTitle: Get scroll position
language: javascript
tags: [browser]
cover: tranquil-lake
excerpt: Calculate the coordinates of the current scroll position in the browser window using JavaScript.
listed: true
dateModified: 2024-02-25
---
JavaScrip... | code_snippets | ||
4114b54a-aaac-409d-b2fd-326fd1b8a68d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/generator-to-array.md | unknown | 673baec1-d46a-43b9-9edd-af94241e0aeb | 0 | SemanticChunker@1.0.0 | 9f35ee58665eff06fe4086a72e093f0dd0386dd562b773b3577e8641701978eb | ---
title: Convert the output of a JavaScript generator to an array
shortTitle: Generator to array
language: javascript
tags: [function,array,generator]
cover: messy-papers
excerpt: Converts the output of any generator function to an array using the spread operator.
listed: true
dateModified: 2024-08-01
---
When worki... | unknown | unknown | ---
title: Convert the output of a JavaScript generator to an array
shortTitle: Generator to array
language: javascript
tags: [function,array,generator]
cover: messy-papers
excerpt: Converts the output of any generator function to an array using the spread operator.
listed: true
dateModified: 2024-08-01
---
When worki... | ---
title: Convert the output of a JavaScript generator to an array
shortTitle: Generator to array
language: javascript
tags: [function,array,generator]
cover: messy-papers
excerpt: Converts the output of any generator function to an array using the spread operator.
listed: true
dateModified: 2024-08-01
---
When worki... | code_snippets | ||
4d706361-de20-4402-bd58-3115acb5dd08 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-elements-wider-than-viewport.md | unknown | c372e127-de7d-4a9d-92d4-72033d586e26 | 0 | SemanticChunker@1.0.0 | a69e532f7b3cc3c07ad29daff558612ab5d812483c2f30c4f511d21648999f66 | ---
title: Get elements wider than the viewport with JavaScript
shortTitle: Elements wider than viewport
language: javascript
tags: [browser]
cover: case-study
excerpt: Ever had elements that horizontally overflow the viewport? This JavaScript function can help you identify them.
listed: true
dateModified: 2024-07-14
-... | unknown | unknown | ---
title: Get elements wider than the viewport with JavaScript
shortTitle: Elements wider than viewport
language: javascript
tags: [browser]
cover: case-study
excerpt: Ever had elements that horizontally overflow the viewport? This JavaScript function can help you identify them.
listed: true
dateModified: 2024-07-14
-... | ---
title: Get elements wider than the viewport with JavaScript
shortTitle: Elements wider than viewport
language: javascript
tags: [browser]
cover: case-study
excerpt: Ever had elements that horizontally overflow the viewport? This JavaScript function can help you identify them.
listed: true
dateModified: 2024-07-14
-... | code_snippets | ||
c0294f36-7de1-4144-9b56-828b8746546b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/generate-while.md | unknown | fe25a148-4600-4870-8f42-c2f40c453025 | 0 | SemanticChunker@1.0.0 | 6bf4f74fc415874964ada51e02a2d08cfc08730bf4ae477e288117ca0997255e | ---
title: Create a JavaScript generator function based on a condition
shortTitle: Generate while condition is met
language: javascript
tags: [function,generator]
cover: yellow-sofa
excerpt: Learn how to create a generator function that keeps producing new values as long as the given condition is met.
listed: true
date... | unknown | unknown | ---
title: Create a JavaScript generator function based on a condition
shortTitle: Generate while condition is met
language: javascript
tags: [function,generator]
cover: yellow-sofa
excerpt: Learn how to create a generator function that keeps producing new values as long as the given condition is met.
listed: true
date... | ---
title: Create a JavaScript generator function based on a condition
shortTitle: Generate while condition is met
language: javascript
tags: [function,generator]
cover: yellow-sofa
excerpt: Learn how to create a generator function that keeps producing new values as long as the given condition is met.
listed: true
date... | code_snippets | ||
40dfd688-a9cb-419d-b822-a2e5469ab6be | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-colon-time-from-date.md | unknown | 8a2efe92-63f9-4bef-a411-fac98310cedb | 0 | SemanticChunker@1.0.0 | 2a73374d038a1574a0bbc041eb429271470d3f7a8c9576887bc76923cc7db87b | ---
title: Get colon time from a JavaScript date
shortTitle: Colon time from date
language: javascript
tags: [date,string]
cover: digital-nomad-5
excerpt: Get the time part of a Date object in the format HH:MM:SS.
listed: true
dateModified: 2024-05-30
---
JavaScript's `Date` objects contain a lot of information, inclu... | unknown | unknown | ---
title: Get colon time from a JavaScript date
shortTitle: Colon time from date
language: javascript
tags: [date,string]
cover: digital-nomad-5
excerpt: Get the time part of a Date object in the format HH:MM:SS.
listed: true
dateModified: 2024-05-30
---
JavaScript's `Date` objects contain a lot of information, inclu... | ---
title: Get colon time from a JavaScript date
shortTitle: Colon time from date
language: javascript
tags: [date,string]
cover: digital-nomad-5
excerpt: Get the time part of a Date object in the format HH:MM:SS.
listed: true
dateModified: 2024-05-30
---
JavaScript's `Date` objects contain a lot of information, inclu... | code_snippets | ||
33f379e8-50ad-4e59-9a8f-facc4f3eb878 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/generate-values-repeatedly.md | unknown | bbf6d538-babb-458d-b10f-5f27e275979f | 0 | SemanticChunker@1.0.0 | 007398f258395f9453f5233f5f771d12c87bb2eb940fd81a97d43b8852ec6a8e | ---
title: How can I create a JavaScript generator function that repeats one or more values indefinitely?
short: Generate values repeatedly
language: javascript
tags: [function,generator]
cover: secret-tree
excerpt: Learn how to create a generator function that repeats a given value or an array of values indefinitely.
... | unknown | unknown | ---
title: How can I create a JavaScript generator function that repeats one or more values indefinitely?
short: Generate values repeatedly
language: javascript
tags: [function,generator]
cover: secret-tree
excerpt: Learn how to create a generator function that repeats a given value or an array of values indefinitely.
... | ---
title: How can I create a JavaScript generator function that repeats one or more values indefinitely?
short: Generate values repeatedly
language: javascript
tags: [function,generator]
cover: secret-tree
excerpt: Learn how to create a generator function that repeats a given value or an array of values indefinitely.
... | code_snippets | ||
37d03aa1-7aee-433f-bc96-d0ac74e2ca42 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/generate-values-repeatedly.md | unknown | bbf6d538-babb-458d-b10f-5f27e275979f | 2 | SemanticChunker@1.0.0 | 3f0a8897fb22c15bb3cf8f1c2ade3362682c77c0861fc698d2db11391de76497 | [Repeating a single value > Repeating an array of values]
## Repeating an array of values
To create a generator that **repeats an array of values** indefinitely, you can use the same approach as before for the non-terminating `while` loop and `yield` a value every time `Generator.prototype.next()` is called. In order... | unknown | unknown | [Repeating a single value > Repeating an array of values]
## Repeating an array of values
To create a generator that **repeats an array of values** indefinitely, you can use the same approach as before for the non-terminating `while` loop and `yield` a value every time `Generator.prototype.next()` is called. In order... | [Repeating a single value > Repeating an array of values]
## Repeating an array of values
To create a generator that **repeats an array of values** indefinitely, you can use the same approach as before for the non-terminating `while` loop and `yield` a value every time `Generator.prototype.next()` is called. In order... | code_snippets | ||
be77c051-dbf7-442b-81d1-bc3630e3589c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/generate-values-repeatedly.md | unknown | bbf6d538-babb-458d-b10f-5f27e275979f | 1 | SemanticChunker@1.0.0 | f55c9218461508402c8fc7eee0f0d116f1d9fae322813a7cb25a49cdd9a38b71 | [Repeating a single value]
## Repeating a single value
To create a generator that **repeats a single value** indefinitely, you can use a non-terminating `while` loop, that will `yield` a value every time `Generator.prototype.next()` is called. You can also use the return value of the `yield` statement to **update the... | unknown | unknown | [Repeating a single value]
## Repeating a single value
To create a generator that **repeats a single value** indefinitely, you can use a non-terminating `while` loop, that will `yield` a value every time `Generator.prototype.next()` is called. You can also use the return value of the `yield` statement to **update the... | [Repeating a single value]
## Repeating a single value
To create a generator that **repeats a single value** indefinitely, you can use a non-terminating `while` loop, that will `yield` a value every time `Generator.prototype.next()` is called. You can also use the return value of the `yield` statement to **update the... | code_snippets | ||
70d15bd1-a353-4336-aa26-c33f21bde3b4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-nested-object-value.md | unknown | e884a4fa-3969-4371-b451-1c837a2a1532 | 0 | SemanticChunker@1.0.0 | 1ded154892cb90bc71e64de203368c07a307985a969f1e932385c5f589c2f948 | ---
title: Get a nested object property by key or path in JavaScript
shortTitle: Get nested object property
language: javascript
tags: [object,regexp,recursion]
cover: campfire
excerpt: Learn how to get a nested object property by key or a path string in JavaScript, and how to search for nested values in an object.
lis... | unknown | unknown | ---
title: Get a nested object property by key or path in JavaScript
shortTitle: Get nested object property
language: javascript
tags: [object,regexp,recursion]
cover: campfire
excerpt: Learn how to get a nested object property by key or a path string in JavaScript, and how to search for nested values in an object.
lis... | ---
title: Get a nested object property by key or path in JavaScript
shortTitle: Get nested object property
language: javascript
tags: [object,regexp,recursion]
cover: campfire
excerpt: Learn how to get a nested object property by key or a path string in JavaScript, and how to search for nested values in an object.
lis... | code_snippets | ||
a9527fd4-3d80-4410-93e9-9f95a0e9219e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-nested-object-value.md | unknown | e884a4fa-3969-4371-b451-1c837a2a1532 | 1 | SemanticChunker@1.0.0 | 4fa9e3ff5f98f55b54c677e9985e8ea03355688b0f5868db4c7d4436fabf7fd9 | [Use an array of keys to get a nested object property]
## Use an array of keys to get a nested object property
The simplest scenario and by far the most common is having an **array of keys** that represent the path to the desired property in the object. In that case, all you need to do is use `Array.prototype.reduce(... | unknown | unknown | [Use an array of keys to get a nested object property]
## Use an array of keys to get a nested object property
The simplest scenario and by far the most common is having an **array of keys** that represent the path to the desired property in the object. In that case, all you need to do is use `Array.prototype.reduce(... | [Use an array of keys to get a nested object property]
## Use an array of keys to get a nested object property
The simplest scenario and by far the most common is having an **array of keys** that represent the path to the desired property in the object. In that case, all you need to do is use `Array.prototype.reduce(... | code_snippets | ||
c6cb2897-667f-43d2-8e98-a86d779cb198 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-nested-object-value.md | unknown | e884a4fa-3969-4371-b451-1c837a2a1532 | 3 | SemanticChunker@1.0.0 | d51d2c7c23dbe2df85246e2c942c3194fc62a41239e55abeee7fd75fea24c175 | [Use an array of keys to get a nested object property > Search for a deeply nested property in an object]
## Search for a deeply nested property in an object
Another unusual scenario is searching for a deeply nested property in an object. This is useful when you **don't know the exact path** to the property, but you ... | unknown | unknown | [Use an array of keys to get a nested object property > Search for a deeply nested property in an object]
## Search for a deeply nested property in an object
Another unusual scenario is searching for a deeply nested property in an object. This is useful when you **don't know the exact path** to the property, but you ... | [Use an array of keys to get a nested object property > Search for a deeply nested property in an object]
## Search for a deeply nested property in an object
Another unusual scenario is searching for a deeply nested property in an object. This is useful when you **don't know the exact path** to the property, but you ... | code_snippets | ||
db7ce45c-aaf4-44b6-8a43-c292fb0b5482 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-nested-object-value.md | unknown | e884a4fa-3969-4371-b451-1c837a2a1532 | 2 | SemanticChunker@1.0.0 | 1e41b56c893068815cad73df863c679568254910c28f297152ddfd88f16113a6 | [Use an array of keys to get a nested object property > Use path strings to get nested object properties]
## Use path strings to get nested object properties
A less common, yet more complex use-case is when you need to get a nested object property based on a **path string**. This is useful when you have a string that... | unknown | unknown | [Use an array of keys to get a nested object property > Use path strings to get nested object properties]
## Use path strings to get nested object properties
A less common, yet more complex use-case is when you need to get a nested object property based on a **path string**. This is useful when you have a string that... | [Use an array of keys to get a nested object property > Use path strings to get nested object properties]
## Use path strings to get nested object properties
A less common, yet more complex use-case is when you need to get a nested object property based on a **path string**. This is useful when you have a string that... | code_snippets | ||
1f7f1e42-b76b-4767-84cc-bfd582d43a33 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/heapsort.md | unknown | ba44abc7-bf55-4fee-8eb3-cb438b62f64d | 0 | SemanticChunker@1.0.0 | 85eddd8060f8e7789a3a19d44db843ac6f7e24dff57cb788db5c77572cae43fe | ---
title: Heap sort
language: javascript
tags: [algorithm,array,recursion]
cover: building-blocks
excerpt: Sort an array of numbers, using the heapsort algorithm.
listed: true
dateModified: 2023-12-16
--- | unknown | unknown | ---
title: Heap sort
language: javascript
tags: [algorithm,array,recursion]
cover: building-blocks
excerpt: Sort an array of numbers, using the heapsort algorithm.
listed: true
dateModified: 2023-12-16
--- | ---
title: Heap sort
language: javascript
tags: [algorithm,array,recursion]
cover: building-blocks
excerpt: Sort an array of numbers, using the heapsort algorithm.
listed: true
dateModified: 2023-12-16
--- | code_snippets | ||
529d817c-e03a-47ee-aa77-dfc028f74e19 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/heapsort.md | unknown | ba44abc7-bf55-4fee-8eb3-cb438b62f64d | 1 | SemanticChunker@1.0.0 | 98a0370885861d490b90f61a013a0b22dd59b11c892308ea634dec7e3fb68805 | [Definition]
## Definition
[Heapsort](https://en.wikipedia.org/wiki/Heapsort) is a **comparison-based sorting algorithm**. Heapsort can be thought of as an improved [selection sort](/js/s/selection-sort). The improvement consists of the use of a **heap data structure** instead of a linear-time search to find the maxi... | unknown | unknown | [Definition]
## Definition
[Heapsort](https://en.wikipedia.org/wiki/Heapsort) is a **comparison-based sorting algorithm**. Heapsort can be thought of as an improved [selection sort](/js/s/selection-sort). The improvement consists of the use of a **heap data structure** instead of a linear-time search to find the maxi... | [Definition]
## Definition
[Heapsort](https://en.wikipedia.org/wiki/Heapsort) is a **comparison-based sorting algorithm**. Heapsort can be thought of as an improved [selection sort](/js/s/selection-sort). The improvement consists of the use of a **heap data structure** instead of a linear-time search to find the maxi... | code_snippets | ||
a3ff3366-3566-44d8-92bf-05167a451399 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/heapsort.md | unknown | ba44abc7-bf55-4fee-8eb3-cb438b62f64d | 2 | SemanticChunker@1.0.0 | a8d826d20341eddd54e397da3d3b504e567246085f14e1e2da1dfbcc0f794be2 | [Definition > Implementation]
## Implementation
- Use recursion.
- Use the spread operator (`...`) to clone the original array, `arr`.
- Use closures to declare a variable, `l`, and a function `heapify`.
- Use a `for` loop and `Math.floor()` in combination with `heapify` to create a max heap from the array.
- Use a `... | unknown | unknown | [Definition > Implementation]
## Implementation
- Use recursion.
- Use the spread operator (`...`) to clone the original array, `arr`.
- Use closures to declare a variable, `l`, and a function `heapify`.
- Use a `for` loop and `Math.floor()` in combination with `heapify` to create a max heap from the array.
- Use a `... | [Definition > Implementation]
## Implementation
- Use recursion.
- Use the spread operator (`...`) to clone the original array, `arr`.
- Use closures to declare a variable, `l`, and a function `heapify`.
- Use a `for` loop and `Math.floor()` in combination with `heapify` to create a max heap from the array.
- Use a `... | code_snippets | ||
6dcd133a-d245-4c9c-961c-86cf95fb2234 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/hash-sha-256.md | unknown | 79ed1e01-b8d9-48a9-88dd-154d5c2169b6 | 1 | SemanticChunker@1.0.0 | c7cf5a11cc7bbf548d005f3b29d1ba349b7603f83e387423245d3d953ac7d400 | [Browser]
## Browser
In the browser, you can use the [SubtleCrypto](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) API to create a hash for the given value. You first need to create a new `TextEncoder` and use it to encode the given value. Then, pass its value to `SubtleCrypto.digest()` to generate a ... | unknown | unknown | [Browser]
## Browser
In the browser, you can use the [SubtleCrypto](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) API to create a hash for the given value. You first need to create a new `TextEncoder` and use it to encode the given value. Then, pass its value to `SubtleCrypto.digest()` to generate a ... | [Browser]
## Browser
In the browser, you can use the [SubtleCrypto](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) API to create a hash for the given value. You first need to create a new `TextEncoder` and use it to encode the given value. Then, pass its value to `SubtleCrypto.digest()` to generate a ... | code_snippets | ||
7c123ae2-3da1-49ea-aa8f-d903d90288c6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/hash-sha-256.md | unknown | 79ed1e01-b8d9-48a9-88dd-154d5c2169b6 | 2 | SemanticChunker@1.0.0 | a1898d8f84a977906c2e0ff1ee9f9c46736a8d82d11ecc871bae5aac4aa0e9cf | [Browser > Node.js]
## Node.js
In Node.js, you can use the `crypto` module to create a hash for the given value. You first need to create a `Hash` object with the appropriate algorithm using `crypto.createHash()`. Then, use `hash.update()` to add the data from `val` to the `Hash` and `hash.digest()` to calculate the ... | unknown | unknown | [Browser > Node.js]
## Node.js
In Node.js, you can use the `crypto` module to create a hash for the given value. You first need to create a `Hash` object with the appropriate algorithm using `crypto.createHash()`. Then, use `hash.update()` to add the data from `val` to the `Hash` and `hash.digest()` to calculate the ... | [Browser > Node.js]
## Node.js
In Node.js, you can use the `crypto` module to create a hash for the given value. You first need to create a `Hash` object with the appropriate algorithm using `crypto.createHash()`. Then, use `hash.update()` to add the data from `val` to the `Hash` and `hash.digest()` to calculate the ... | code_snippets | ||
a27307e6-b8dd-43d9-b86a-e18fd1273b86 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/hash-sha-256.md | unknown | 79ed1e01-b8d9-48a9-88dd-154d5c2169b6 | 3 | SemanticChunker@1.0.0 | 3bf22230fab727c22e7b7fe0737bf51968570c2eec65dd1bf29ba9f9e41971de | [Browser > Notes]
## Notes
- The two implementations are **not compatible** with each other. You cannot use the browser implementation in Node.js and vice versa.
- Both implementations should produce the same result for the same input. | unknown | unknown | [Browser > Notes]
## Notes
- The two implementations are **not compatible** with each other. You cannot use the browser implementation in Node.js and vice versa.
- Both implementations should produce the same result for the same input. | [Browser > Notes]
## Notes
- The two implementations are **not compatible** with each other. You cannot use the browser implementation in Node.js and vice versa.
- Both implementations should produce the same result for the same input. | code_snippets | ||
ca88e4bc-7a0e-40c0-a23b-a11b0e919485 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/hash-sha-256.md | unknown | 79ed1e01-b8d9-48a9-88dd-154d5c2169b6 | 0 | SemanticChunker@1.0.0 | 7e340006201a1e80e2a61140b044e1dbd507bc27c83b1bc6902580fb023af26d | ---
title: Calculate SHA-256 hash in JavaScript
shortTitle: SHA-256 hash
language: javascript
tags: [browser,node,promises]
cover: padlocks
excerpt: Calculate a SHA-256 hash in JavaScript using native APIs in both the browser and Node.js.
listed: true
dateModified: 2023-10-07
---
The [SHA-256](https://en.wikipedia.org... | unknown | unknown | ---
title: Calculate SHA-256 hash in JavaScript
shortTitle: SHA-256 hash
language: javascript
tags: [browser,node,promises]
cover: padlocks
excerpt: Calculate a SHA-256 hash in JavaScript using native APIs in both the browser and Node.js.
listed: true
dateModified: 2023-10-07
---
The [SHA-256](https://en.wikipedia.org... | ---
title: Calculate SHA-256 hash in JavaScript
shortTitle: SHA-256 hash
language: javascript
tags: [browser,node,promises]
cover: padlocks
excerpt: Calculate a SHA-256 hash in JavaScript using native APIs in both the browser and Node.js.
listed: true
dateModified: 2023-10-07
---
The [SHA-256](https://en.wikipedia.org... | code_snippets | ||
be354118-b9f8-4890-9e78-b801b68d4881 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/hamming-distance.md | unknown | 4d1d0448-e03e-4329-9282-410f957afae9 | 0 | SemanticChunker@1.0.0 | c1c798dac74c49c821c486659380ae4f9ed1addfb64860aef4f51223ed4f6cce | ---
title: Hamming distance implementation in JavaScript
shortTitle: Hamming distance
language: javascript
tags: [math,algorithm]
cover: colorful-lounge
excerpt: Learn how to calculate the Hamming distance between two values.
listed: true
dateModified: 2024-07-18
---
The [Hamming distance](https://en.wikipedia.org/wik... | unknown | unknown | ---
title: Hamming distance implementation in JavaScript
shortTitle: Hamming distance
language: javascript
tags: [math,algorithm]
cover: colorful-lounge
excerpt: Learn how to calculate the Hamming distance between two values.
listed: true
dateModified: 2024-07-18
---
The [Hamming distance](https://en.wikipedia.org/wik... | ---
title: Hamming distance implementation in JavaScript
shortTitle: Hamming distance
language: javascript
tags: [math,algorithm]
cover: colorful-lounge
excerpt: Learn how to calculate the Hamming distance between two values.
listed: true
dateModified: 2024-07-18
---
The [Hamming distance](https://en.wikipedia.org/wik... | code_snippets | ||
cac42a34-b959-49fc-9840-2143e3a2b934 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/hash-string-into-number.md | unknown | cf0a6808-faa5-4e2c-bf89-6738f414ca8e | 0 | SemanticChunker@1.0.0 | 4d746a5e7a6af605c4b93e125b6861fa29224912f15baff1a68b7a079d860dd6 | ---
title: Implement the SDBM hash function in JavaScript
shortTitle: Hash string into number
language: javascript
tags: [math]
cover: cloudy-lake-reflection
excerpt: SDBM is a simple, non-cryptographic hash function that can hash strings into whole numbers. Here's a JavaScript implementation.
listed: true
dateModified... | unknown | unknown | ---
title: Implement the SDBM hash function in JavaScript
shortTitle: Hash string into number
language: javascript
tags: [math]
cover: cloudy-lake-reflection
excerpt: SDBM is a simple, non-cryptographic hash function that can hash strings into whole numbers. Here's a JavaScript implementation.
listed: true
dateModified... | ---
title: Implement the SDBM hash function in JavaScript
shortTitle: Hash string into number
language: javascript
tags: [math]
cover: cloudy-lake-reflection
excerpt: SDBM is a simple, non-cryptographic hash function that can hash strings into whole numbers. Here's a JavaScript implementation.
listed: true
dateModified... | code_snippets | ||
a69863a6-8b35-431e-ac39-15ba56b26c1a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/group-array-elements.md | unknown | c658ef46-1039-453f-9b32-010f23d256aa | 0 | SemanticChunker@1.0.0 | 03f2463a5d21dcb04384bbb33d3f2da9d5b5a437b47be7297b43ad2206e87690 | ---
title: Group array elements based on a function
shortTitle: Group array elements
language: javascript
tags: [array,object]
cover: man-cup-laptop
excerpt: Group the elements of an array based on the given function, producing an object with the grouped values.
listed: true
dateModified: 2024-07-13
---
While JavaScri... | unknown | unknown | ---
title: Group array elements based on a function
shortTitle: Group array elements
language: javascript
tags: [array,object]
cover: man-cup-laptop
excerpt: Group the elements of an array based on the given function, producing an object with the grouped values.
listed: true
dateModified: 2024-07-13
---
While JavaScri... | ---
title: Group array elements based on a function
shortTitle: Group array elements
language: javascript
tags: [array,object]
cover: man-cup-laptop
excerpt: Group the elements of an array based on the given function, producing an object with the grouped values.
listed: true
dateModified: 2024-07-13
---
While JavaScri... | code_snippets | ||
e42fb849-05be-462b-8c1d-c197af7974b1 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-vertical-offset.md | unknown | 1d9a7a28-9666-4a23-8c80-e4165c7376ff | 0 | SemanticChunker@1.0.0 | a387b6d6e4f898b9b5499af3f8d564f4315e6c885874c79e06aeaec23102943f | ---
title: Vertical offset of an element in the document
shortTitle: Vertical offset of an element
language: javascript
tags: [browser]
cover: waves-from-above-2
excerpt: Find the distance from a given element to the top of the document with this simple JavaScript function.
listed: true
dateModified: 2024-07-15
---
Ca... | unknown | unknown | ---
title: Vertical offset of an element in the document
shortTitle: Vertical offset of an element
language: javascript
tags: [browser]
cover: waves-from-above-2
excerpt: Find the distance from a given element to the top of the document with this simple JavaScript function.
listed: true
dateModified: 2024-07-15
---
Ca... | ---
title: Vertical offset of an element in the document
shortTitle: Vertical offset of an element
language: javascript
tags: [browser]
cover: waves-from-above-2
excerpt: Find the distance from a given element to the top of the document with this simple JavaScript function.
listed: true
dateModified: 2024-07-15
---
Ca... | code_snippets | ||
0f521b19-e1f7-42c4-ad57-84a87e6b42a7 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-set-add-styles-to-html-element.md | unknown | 4430f82a-b5c6-4e9d-bc48-4dada8cba657 | 3 | SemanticChunker@1.0.0 | 32e59abb65852d0a9c4b021a6428c8e4f7a63cdca570d3420332288680a609e9 | [Get the styles of an HTML element > Add styles to an HTML element]
## Add styles to an HTML element
Given that the `HTMLElement.style` property is an object, you can use `Object.assign()` to **merge any given styles object** into the style of the given element. This allows you to add **multiple styles** at once.
``... | unknown | unknown | [Get the styles of an HTML element > Add styles to an HTML element]
## Add styles to an HTML element
Given that the `HTMLElement.style` property is an object, you can use `Object.assign()` to **merge any given styles object** into the style of the given element. This allows you to add **multiple styles** at once.
``... | [Get the styles of an HTML element > Add styles to an HTML element]
## Add styles to an HTML element
Given that the `HTMLElement.style` property is an object, you can use `Object.assign()` to **merge any given styles object** into the style of the given element. This allows you to add **multiple styles** at once.
``... | code_snippets | ||
637ca592-e44b-4c31-aea7-671bb5bcec8a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-set-add-styles-to-html-element.md | unknown | 4430f82a-b5c6-4e9d-bc48-4dada8cba657 | 1 | SemanticChunker@1.0.0 | 680b8188b589a3b7460e9e182a62f678d70bccc69e98dee5d60ae411e5fcbae6 | [Get the styles of an HTML element]
## Get the styles of an HTML element
In order to **retrieve the styles** of an HTML element, you can use `Window.getComputedStyle()`. The resulting value is a `CSSStyleDeclaration` object, which contains the styles of the element. Then, all you have to do is **access the desired at... | unknown | unknown | [Get the styles of an HTML element]
## Get the styles of an HTML element
In order to **retrieve the styles** of an HTML element, you can use `Window.getComputedStyle()`. The resulting value is a `CSSStyleDeclaration` object, which contains the styles of the element. Then, all you have to do is **access the desired at... | [Get the styles of an HTML element]
## Get the styles of an HTML element
In order to **retrieve the styles** of an HTML element, you can use `Window.getComputedStyle()`. The resulting value is a `CSSStyleDeclaration` object, which contains the styles of the element. Then, all you have to do is **access the desired at... | code_snippets | ||
88abcf0a-9ccf-41b7-ab87-7a99b068f839 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-set-add-styles-to-html-element.md | unknown | 4430f82a-b5c6-4e9d-bc48-4dada8cba657 | 2 | SemanticChunker@1.0.0 | d7d9a71d52f8f9051208b9c1ad92f90a9bcb7ac71d21c93554d4032312f662ee | [Get the styles of an HTML element > Set the styles of an HTML element]
## Set the styles of an HTML element
Setting the value of a CSS attribute is just as simple, using the `HTMLElement.style` property. Again, you can access the desired attribute and set its value, similar to how you would with an **object**.
```j... | unknown | unknown | [Get the styles of an HTML element > Set the styles of an HTML element]
## Set the styles of an HTML element
Setting the value of a CSS attribute is just as simple, using the `HTMLElement.style` property. Again, you can access the desired attribute and set its value, similar to how you would with an **object**.
```j... | [Get the styles of an HTML element > Set the styles of an HTML element]
## Set the styles of an HTML element
Setting the value of a CSS attribute is just as simple, using the `HTMLElement.style` property. Again, you can access the desired attribute and set its value, similar to how you would with an **object**.
```j... | code_snippets | ||
da9c9664-7cf1-414c-9fd2-0b5f3deb71f5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-set-add-styles-to-html-element.md | unknown | 4430f82a-b5c6-4e9d-bc48-4dada8cba657 | 0 | SemanticChunker@1.0.0 | 9e99ee2ccf9c0bdf2d12e7875e312b0a738ca83d4f6e21d0d55caa3a1cda7fe7 | ---
title: Get, set or add styles to an HTML element with JavaScript
shortTitle: Get, set or add styles to an HTML element
language: javascript
tags: [browser,css]
cover: frog-blue-flower
excerpt: Learn how to retrieve and manipulate the styles of an HTML element easily and efficiently with JavaScript.
listed: true
dat... | unknown | unknown | ---
title: Get, set or add styles to an HTML element with JavaScript
shortTitle: Get, set or add styles to an HTML element
language: javascript
tags: [browser,css]
cover: frog-blue-flower
excerpt: Learn how to retrieve and manipulate the styles of an HTML element easily and efficiently with JavaScript.
listed: true
dat... | ---
title: Get, set or add styles to an HTML element with JavaScript
shortTitle: Get, set or add styles to an HTML element
language: javascript
tags: [browser,css]
cover: frog-blue-flower
excerpt: Learn how to retrieve and manipulate the styles of an HTML element easily and efficiently with JavaScript.
listed: true
dat... | code_snippets | ||
8450ef16-02d0-45c0-be1f-16a9fde68c36 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-selected-text.md | unknown | d4293452-fe19-4a7e-80f2-a4c5583f23f8 | 0 | SemanticChunker@1.0.0 | b3aad097322dd9d0f90eaa03a727d1fd077d0dae7c29a2d0aaf022771f83a1f9 | ---
title: How can I get the currently selected text in the browser?
shortTitle: Get selected text
language: javascript
tags: [browser]
cover: white-tablet-2
excerpt: Learn how to get the currently selected text in the browser using JavaScript.
listed: true
dateModified: 2024-07-16
---
When working with text in the br... | unknown | unknown | ---
title: How can I get the currently selected text in the browser?
shortTitle: Get selected text
language: javascript
tags: [browser]
cover: white-tablet-2
excerpt: Learn how to get the currently selected text in the browser using JavaScript.
listed: true
dateModified: 2024-07-16
---
When working with text in the br... | ---
title: How can I get the currently selected text in the browser?
shortTitle: Get selected text
language: javascript
tags: [browser]
cover: white-tablet-2
excerpt: Learn how to get the currently selected text in the browser using JavaScript.
listed: true
dateModified: 2024-07-16
---
When working with text in the br... | code_snippets | ||
61bfb33c-df74-4e62-b0ea-9c257b5aa414 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/higher-order-functions.md | unknown | ae15c524-8364-4f8d-a3d5-0592b56ae606 | 0 | SemanticChunker@1.0.0 | 5311741776f5ebd6b5f2f2ce463448207f2b3a7c5b35e870f069466936a51e7e | ---
title: Understanding higher-order functions in JavaScript
shortTitle: Higher-order functions
language: javascript
tags: [function]
cover: rock-climbing
excerpt: Learn everything you need to know about higher-order functions with this short guide and level up your programming skills.
listed: true
dateModified: 2021-... | unknown | unknown | ---
title: Understanding higher-order functions in JavaScript
shortTitle: Higher-order functions
language: javascript
tags: [function]
cover: rock-climbing
excerpt: Learn everything you need to know about higher-order functions with this short guide and level up your programming skills.
listed: true
dateModified: 2021-... | ---
title: Understanding higher-order functions in JavaScript
shortTitle: Higher-order functions
language: javascript
tags: [function]
cover: rock-climbing
excerpt: Learn everything you need to know about higher-order functions with this short guide and level up your programming skills.
listed: true
dateModified: 2021-... | code_snippets | ||
867af8bf-fc4f-42fe-9405-f2c1eaa86327 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/higher-order-functions.md | unknown | ae15c524-8364-4f8d-a3d5-0592b56ae606 | 1 | SemanticChunker@1.0.0 | d0d8eeed6795015c78f505ab5095f53c1e5eab11bd75e6b487a9073e5ca43eaa | In this example, we define two simple functions that we then use as callbacks in `Array.prototype.reduce()` and `Array.prototype.filter()` to get the result we want. Both of these functions are higher-order functions. This allows us to create an **abstraction layer for any action** we might want to perform without havi... | unknown | unknown | In this example, we define two simple functions that we then use as callbacks in `Array.prototype.reduce()` and `Array.prototype.filter()` to get the result we want. Both of these functions are higher-order functions. This allows us to create an **abstraction layer for any action** we might want to perform without havi... | In this example, we define two simple functions that we then use as callbacks in `Array.prototype.reduce()` and `Array.prototype.filter()` to get the result we want. Both of these functions are higher-order functions. This allows us to create an **abstraction layer for any action** we might want to perform without havi... | code_snippets | ||
5503d3dd-9d6e-4340-8c72-8ac0434a9840 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/get-scrollbar-width.md | unknown | 574b364d-c191-4d1a-b956-762cf323d17e | 0 | SemanticChunker@1.0.0 | a1f8f8495a25eb0c6b3226c1b76ffc880cbcd6f5843a786e2c5bd0a282903a8e | ---
title: Get the width of the scrollbar using JavaScript
shortTitle: Get scrollbar width
language: javascript
tags: [browser]
cover: violin
excerpt: Easily and reliably calculate the width of the browser's vertical scrollbar with JavaScript.
listed: true
dateModified: 2024-02-24
---
When working in a browser environ... | unknown | unknown | ---
title: Get the width of the scrollbar using JavaScript
shortTitle: Get scrollbar width
language: javascript
tags: [browser]
cover: violin
excerpt: Easily and reliably calculate the width of the browser's vertical scrollbar with JavaScript.
listed: true
dateModified: 2024-02-24
---
When working in a browser environ... | ---
title: Get the width of the scrollbar using JavaScript
shortTitle: Get scrollbar width
language: javascript
tags: [browser]
cover: violin
excerpt: Easily and reliably calculate the width of the browser's vertical scrollbar with JavaScript.
listed: true
dateModified: 2024-02-24
---
When working in a browser environ... | code_snippets | ||
0057d0cd-3a3f-44b8-9473-721bf0c6478f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/immutable-object-proxy.md | unknown | 5fe1c41e-1f4c-425e-badf-58c0a7f3489d | 0 | SemanticChunker@1.0.0 | 5ea296c20d842ca66e992fffbe94cc589ca8e4d1ad88a6302486249387b41dcf | ---
title: Immutable JavaScript objects using the Proxy object
shortTitle: Immutable objects using Proxy
language: javascript
tags: [proxy]
cover: frozen-globe
excerpt: Freezing objects is not the only way to prevent mutations. Learn how you can leverage the Proxy object to your advantage.
listed: true
dateModified: 20... | unknown | unknown | ---
title: Immutable JavaScript objects using the Proxy object
shortTitle: Immutable objects using Proxy
language: javascript
tags: [proxy]
cover: frozen-globe
excerpt: Freezing objects is not the only way to prevent mutations. Learn how you can leverage the Proxy object to your advantage.
listed: true
dateModified: 20... | ---
title: Immutable JavaScript objects using the Proxy object
shortTitle: Immutable objects using Proxy
language: javascript
tags: [proxy]
cover: frozen-globe
excerpt: Freezing objects is not the only way to prevent mutations. Learn how you can leverage the Proxy object to your advantage.
listed: true
dateModified: 20... | code_snippets | ||
6c658451-6e33-4281-a2f0-6d12c2852cd4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/immutable-object-proxy.md | unknown | 5fe1c41e-1f4c-425e-badf-58c0a7f3489d | 1 | SemanticChunker@1.0.0 | b25b0e77ca62fcf6b06d270b61cda1a93fe7ae10e4d007a4881775bdd13319dc | Even though proxies are not all that common, this code shouldn't be hard to understand. The gist of the idea is that you use a handler to **prevent mutations to the object** via the `set()` trap. Additionally, you use the `get()` trap to **enforce immutability on all nested values**. This is done by checking the type o... | unknown | unknown | Even though proxies are not all that common, this code shouldn't be hard to understand. The gist of the idea is that you use a handler to **prevent mutations to the object** via the `set()` trap. Additionally, you use the `get()` trap to **enforce immutability on all nested values**. This is done by checking the type o... | Even though proxies are not all that common, this code shouldn't be hard to understand. The gist of the idea is that you use a handler to **prevent mutations to the object** via the `set()` trap. Additionally, you use the `get()` trap to **enforce immutability on all nested values**. This is done by checking the type o... | code_snippets | ||
50512532-6ce6-4cd9-b529-6870f07b4bc7 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/includes-case-insensitive.md | unknown | e193969f-2978-4222-963a-2ccf578805e2 | 0 | SemanticChunker@1.0.0 | 7a8f282e24cc104b491889604ced5b21056a9eb9b631628f73c213b2abbbedc0 | ---
title: Can I check if a JavaScript string contains a substring, regardless of case?
shortTitle: Case-insensitive substring search
language: javascript
tags: [string,regexp]
cover: cup-of-orange
excerpt: Search for substrings in JavaScript strings without worrying about case sensitivity.
listed: true
dateModified: 2... | unknown | unknown | ---
title: Can I check if a JavaScript string contains a substring, regardless of case?
shortTitle: Case-insensitive substring search
language: javascript
tags: [string,regexp]
cover: cup-of-orange
excerpt: Search for substrings in JavaScript strings without worrying about case sensitivity.
listed: true
dateModified: 2... | ---
title: Can I check if a JavaScript string contains a substring, regardless of case?
shortTitle: Case-insensitive substring search
language: javascript
tags: [string,regexp]
cover: cup-of-orange
excerpt: Search for substrings in JavaScript strings without worrying about case sensitivity.
listed: true
dateModified: 2... | code_snippets | ||
768652db-9b44-433f-923d-9791815c0a70 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/https-redirect.md | unknown | d23baa5a-38e8-4c3d-9605-7a84f353913b | 0 | SemanticChunker@1.0.0 | 1041431b06112810cb7bc1f8bbffa033d55528977e2ff4ad406394c5f3226f8c | ---
title: How can I redirect the page to HTTPS in JavaScript?
shortTitle: Redirect to HTTPS
language: javascript
tags: [browser]
cover: blue-lake
excerpt: Learn how to redirect the page to HTTPS if it's currently in HTTP.
listed: true
dateModified: 2023-10-18
---
HTTP is a highly **insecure and legacy protocol**, and... | unknown | unknown | ---
title: How can I redirect the page to HTTPS in JavaScript?
shortTitle: Redirect to HTTPS
language: javascript
tags: [browser]
cover: blue-lake
excerpt: Learn how to redirect the page to HTTPS if it's currently in HTTP.
listed: true
dateModified: 2023-10-18
---
HTTP is a highly **insecure and legacy protocol**, and... | ---
title: How can I redirect the page to HTTPS in JavaScript?
shortTitle: Redirect to HTTPS
language: javascript
tags: [browser]
cover: blue-lake
excerpt: Learn how to redirect the page to HTTPS if it's currently in HTTP.
listed: true
dateModified: 2023-10-18
---
HTTP is a highly **insecure and legacy protocol**, and... | code_snippets |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.