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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
f2692d1e-c8ed-4a4c-b136-350b8290bbbe | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/random-hex-color-code.md | unknown | 587ab97c-cb41-418e-a856-fdaea68b62c4 | 0 | SemanticChunker@1.0.0 | dc48405f0f99e8a1f75e5c830c7684610dbfc25084f1234324709f096645637e | ---
title: Generate a random hex color code in JavaScript
shortTitle: Random hex color code
language: javascript
tags: [math,random]
cover: industrial-tokyo
excerpt: Learn how to generate a random hexadecimal color code with a few lines of JavaScript.
listed: true
dateModified: 2024-02-02
---
Hex color codes are used ... | unknown | unknown | ---
title: Generate a random hex color code in JavaScript
shortTitle: Random hex color code
language: javascript
tags: [math,random]
cover: industrial-tokyo
excerpt: Learn how to generate a random hexadecimal color code with a few lines of JavaScript.
listed: true
dateModified: 2024-02-02
---
Hex color codes are used ... | ---
title: Generate a random hex color code in JavaScript
shortTitle: Random hex color code
language: javascript
tags: [math,random]
cover: industrial-tokyo
excerpt: Learn how to generate a random hexadecimal color code with a few lines of JavaScript.
listed: true
dateModified: 2024-02-02
---
Hex color codes are used ... | code_snippets | ||
8fbfcb7f-fdfa-4925-b8cb-4664c49ee172 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/random-integer-array-in-range.md | unknown | 8844abe7-0c94-4c87-9d23-815a5ed04b24 | 0 | SemanticChunker@1.0.0 | 100611d35207fdf5aacb9daba68707b83e503565505e025108572fc57ba43373 | ---
title: Generate a JavaScript array of random integers in a given range
shortTitle: Random integer array in range
language: javascript
tags: [math,random]
cover: digital-nomad-11
excerpt: Combining `Math.random()` and a few simple math operations, you can generate an array of random integers in a specified range.
li... | unknown | unknown | ---
title: Generate a JavaScript array of random integers in a given range
shortTitle: Random integer array in range
language: javascript
tags: [math,random]
cover: digital-nomad-11
excerpt: Combining `Math.random()` and a few simple math operations, you can generate an array of random integers in a specified range.
li... | ---
title: Generate a JavaScript array of random integers in a given range
shortTitle: Random integer array in range
language: javascript
tags: [math,random]
cover: digital-nomad-11
excerpt: Combining `Math.random()` and a few simple math operations, you can generate an array of random integers in a specified range.
li... | code_snippets | ||
2a273f4a-c035-46cc-a0e3-2577bb7c9dde | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/quick-sort.md | unknown | 178ef37b-c288-42a0-9df4-a0201c2f9d72 | 1 | SemanticChunker@1.0.0 | 14e09a42299a9807064000333385d7e9febdba647c88008d9925564f76463a49 | [Definition > Implementation]
## Implementation
- Use recursion.
- Use the spread operator (`...`) to clone the original array, `arr`.
- If the `length` of the array is less than `2`, return the cloned array.
- Use `Math.floor()` to calculate the index of the pivot element.
- Use `Array.prototype.reduce()` and `Array... | unknown | unknown | [Definition > Implementation]
## Implementation
- Use recursion.
- Use the spread operator (`...`) to clone the original array, `arr`.
- If the `length` of the array is less than `2`, return the cloned array.
- Use `Math.floor()` to calculate the index of the pivot element.
- Use `Array.prototype.reduce()` and `Array... | [Definition > Implementation]
## Implementation
- Use recursion.
- Use the spread operator (`...`) to clone the original array, `arr`.
- If the `length` of the array is less than `2`, return the cloned array.
- Use `Math.floor()` to calculate the index of the pivot element.
- Use `Array.prototype.reduce()` and `Array... | code_snippets | ||
f3ce8e76-07f0-4d49-a07e-87a4452ccb08 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/quick-sort.md | unknown | 178ef37b-c288-42a0-9df4-a0201c2f9d72 | 0 | SemanticChunker@1.0.0 | 8607ca8bcf430f27df7ed6ca9f313a9c051f095cf64f7913638987c78aa480ba | [Definition]
## Definition
[Quicksort](https://en.wikipedia.org/wiki/Quicksort) is a **divide and conquer sorting algorithm**. It first divides a large array into two smaller subarrays and then recursively sorts the subarrays. | unknown | unknown | [Definition]
## Definition
[Quicksort](https://en.wikipedia.org/wiki/Quicksort) is a **divide and conquer sorting algorithm**. It first divides a large array into two smaller subarrays and then recursively sorts the subarrays. | [Definition]
## Definition
[Quicksort](https://en.wikipedia.org/wiki/Quicksort) is a **divide and conquer sorting algorithm**. It first divides a large array into two smaller subarrays and then recursively sorts the subarrays. | code_snippets | ||
24f72f7c-e9e1-4f42-980a-59f5d1aa1f40 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/random-number-or-integer-in-range.md | unknown | 11a75535-bec3-49e0-92be-0b0f5887ae4f | 2 | SemanticChunker@1.0.0 | 10a98d0494a7812ddaa9c2120453b9a3912e5bd68005f94057600d94cbdd9972 | [Random number in a range > Random integer in a range]
## Random integer in a range
Subsequently, generating a **random integer** is very similar, except for an additional step at the end. You need to use `Math.floor()` to **round the result down** to the nearest integer.
```js
const randomIntegerInRange = (min, max... | unknown | unknown | [Random number in a range > Random integer in a range]
## Random integer in a range
Subsequently, generating a **random integer** is very similar, except for an additional step at the end. You need to use `Math.floor()` to **round the result down** to the nearest integer.
```js
const randomIntegerInRange = (min, max... | [Random number in a range > Random integer in a range]
## Random integer in a range
Subsequently, generating a **random integer** is very similar, except for an additional step at the end. You need to use `Math.floor()` to **round the result down** to the nearest integer.
```js
const randomIntegerInRange = (min, max... | code_snippets | ||
9feb1697-daec-4eaf-b290-883c3604cb8c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/random-number-or-integer-in-range.md | unknown | 11a75535-bec3-49e0-92be-0b0f5887ae4f | 1 | SemanticChunker@1.0.0 | 4b7a8a5c5351eb0a3652cc77e3086cbc752eafdb823faaccb4ed094d81e4cc35 | [Random number in a range]
## Random number in a range
The simplest use case you'll come across is to generate a **random number in a specified range**. All you need to do is multiply the result of `Math.random()` by the **difference** between the maximum and minimum values, and then add the minimum value.
```js
con... | unknown | unknown | [Random number in a range]
## Random number in a range
The simplest use case you'll come across is to generate a **random number in a specified range**. All you need to do is multiply the result of `Math.random()` by the **difference** between the maximum and minimum values, and then add the minimum value.
```js
con... | [Random number in a range]
## Random number in a range
The simplest use case you'll come across is to generate a **random number in a specified range**. All you need to do is multiply the result of `Math.random()` by the **difference** between the maximum and minimum values, and then add the minimum value.
```js
con... | code_snippets | ||
a91ac413-1a3b-45fb-82d1-b4e202d1e083 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/random-number-or-integer-in-range.md | unknown | 11a75535-bec3-49e0-92be-0b0f5887ae4f | 0 | SemanticChunker@1.0.0 | b44f63cca704c545ddd25a568c8d938805f8361e949bf2b2e5bdb615934b8de0 | ---
title: Generate a random number or integer in a range with JavaScript
shortTitle: Random number or integer in range
language: javascript
tags: [math,random]
cover: white-laptop
excerpt: Enhance JavaScript's `Math.random()` to generate a random number or integer in a specified range.
listed: true
dateModified: 2024-... | unknown | unknown | ---
title: Generate a random number or integer in a range with JavaScript
shortTitle: Random number or integer in range
language: javascript
tags: [math,random]
cover: white-laptop
excerpt: Enhance JavaScript's `Math.random()` to generate a random number or integer in a specified range.
listed: true
dateModified: 2024-... | ---
title: Generate a random number or integer in a range with JavaScript
shortTitle: Random number or integer in range
language: javascript
tags: [math,random]
cover: white-laptop
excerpt: Enhance JavaScript's `Math.random()` to generate a random number or integer in a specified range.
listed: true
dateModified: 2024-... | code_snippets | ||
d348e6d5-b56c-471c-ad66-0ce017e002ac | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/random-number-or-integer-in-range.md | unknown | 11a75535-bec3-49e0-92be-0b0f5887ae4f | 3 | SemanticChunker@1.0.0 | 31027dab97267a74aa830507a7a08a6d577a035def9794a485ef8e6193857ed8 | [Random number in a range > Gaussian random numbers]
## Gaussian random numbers
Finally, if you need to generate Gaussian (**normally distributed**) random numbers, you can use the [Box-Muller transform](https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform) to generate random numbers with a Gaussian distributio... | unknown | unknown | [Random number in a range > Gaussian random numbers]
## Gaussian random numbers
Finally, if you need to generate Gaussian (**normally distributed**) random numbers, you can use the [Box-Muller transform](https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform) to generate random numbers with a Gaussian distributio... | [Random number in a range > Gaussian random numbers]
## Gaussian random numbers
Finally, if you need to generate Gaussian (**normally distributed**) random numbers, you can use the [Box-Muller transform](https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform) to generate random numbers with a Gaussian distributio... | code_snippets | ||
cccc031b-c700-4f10-bba2-7b515b18af7e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/query-selector-shorthand.md | unknown | 390df543-fb28-40c5-a75f-6f598eca2c93 | 0 | SemanticChunker@1.0.0 | c61a60aa92370c7aa6c4a37c12e773e60639f43af4e295010d655218c8625d27 | ---
title: Create your own query selector shorthand in vanilla JavaScript
shortTitle: Query selector shorthand
language: javascript
tags: [browser]
cover: pineapple-at-work
excerpt: Ever wanted to create your own jquery-like query selector shorthand? Here's how!
listed: true
dateModified: 2021-06-12
---
Most of us are... | unknown | unknown | ---
title: Create your own query selector shorthand in vanilla JavaScript
shortTitle: Query selector shorthand
language: javascript
tags: [browser]
cover: pineapple-at-work
excerpt: Ever wanted to create your own jquery-like query selector shorthand? Here's how!
listed: true
dateModified: 2021-06-12
---
Most of us are... | ---
title: Create your own query selector shorthand in vanilla JavaScript
shortTitle: Query selector shorthand
language: javascript
tags: [browser]
cover: pineapple-at-work
excerpt: Ever wanted to create your own jquery-like query selector shorthand? Here's how!
listed: true
dateModified: 2021-06-12
---
Most of us are... | code_snippets | ||
1fc4e582-3c3a-43f5-b31d-5559bbfd4258 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/query-string-to-object.md | unknown | f0497e9e-e554-4e1e-9b6e-b7ee2c64a999 | 0 | SemanticChunker@1.0.0 | 9ae1ef7d8ca79704296e7d9a5d6353f277da794464533ed3fbebc465c391b14a | ---
title: Convert between a query string and an object in JavaScript
shortTitle: Query string to object
language: javascript
tags: [object]
cover: standing-stones
excerpt: Convert between a query string and its object representation in JavaScript.
listed: true
dateModified: 2024-01-20
---
As most web developers know,... | unknown | unknown | ---
title: Convert between a query string and an object in JavaScript
shortTitle: Query string to object
language: javascript
tags: [object]
cover: standing-stones
excerpt: Convert between a query string and its object representation in JavaScript.
listed: true
dateModified: 2024-01-20
---
As most web developers know,... | ---
title: Convert between a query string and an object in JavaScript
shortTitle: Query string to object
language: javascript
tags: [object]
cover: standing-stones
excerpt: Convert between a query string and its object representation in JavaScript.
listed: true
dateModified: 2024-01-20
---
As most web developers know,... | code_snippets | ||
86c1068a-6285-4de0-9d06-48ef00e466ba | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/query-string-to-object.md | unknown | f0497e9e-e554-4e1e-9b6e-b7ee2c64a999 | 1 | SemanticChunker@1.0.0 | 58cb8c7c92c1fed47944fdf8c80beb28045dad20f7db1971e11ea6e176015327 | [Query string to object]
## Query string to object
A query string is, in essence, a **list of key-value pairs**. They are separated from the URL with the `?` character and from each other with the `&` character. Given a `URL` object, we can use `URL.prototype.search` or `URL.prototype.searchParams`. However, we might... | unknown | unknown | [Query string to object]
## Query string to object
A query string is, in essence, a **list of key-value pairs**. They are separated from the URL with the `?` character and from each other with the `&` character. Given a `URL` object, we can use `URL.prototype.search` or `URL.prototype.searchParams`. However, we might... | [Query string to object]
## Query string to object
A query string is, in essence, a **list of key-value pairs**. They are separated from the URL with the `?` character and from each other with the `&` character. Given a `URL` object, we can use `URL.prototype.search` or `URL.prototype.searchParams`. However, we might... | code_snippets | ||
e86340c1-f85d-4fd2-9e19-b4c77238d251 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/query-string-to-object.md | unknown | f0497e9e-e554-4e1e-9b6e-b7ee2c64a999 | 2 | SemanticChunker@1.0.0 | 736982e964749fb9a9b233eb9731db25516437f210757e41771a6958af729fc2 | [Query string to object > Object to query string]
## Object to query string
The opposite operation is just as useful. Given an object, we can create a query string that can be appended to a URL. We can use `Object.entries()` to get an array of key-value pairs. Then, we can use `Array.prototype.reduce()` to create the... | unknown | unknown | [Query string to object > Object to query string]
## Object to query string
The opposite operation is just as useful. Given an object, we can create a query string that can be appended to a URL. We can use `Object.entries()` to get an array of key-value pairs. Then, we can use `Array.prototype.reduce()` to create the... | [Query string to object > Object to query string]
## Object to query string
The opposite operation is just as useful. Given an object, we can create a query string that can be appended to a URL. We can use `Object.entries()` to get an array of key-value pairs. Then, we can use `Array.prototype.reduce()` to create the... | code_snippets | ||
65f9d2be-7500-46d6-b2c3-67bf63f818b5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/reload-module.md | unknown | 09d9a728-6636-45b0-9eb2-fe3e3230f0e1 | 0 | SemanticChunker@1.0.0 | cda2baf206b1bae01ecafa04ef3ae3f600585d0c09813c4f4f500e4cc9ac440b | ---
title: Can I reload a module in Node.js?
shortTitle: Reload a module
language: javascript
tags: [node]
cover: tea-laptop-table
excerpt: Ever wanted to reload a module in Node.js? Here's how you can do it.
listed: true
dateModified: 2024-05-13
---
If you've ever tried to **reload a module** in Node.js, you might ha... | unknown | unknown | ---
title: Can I reload a module in Node.js?
shortTitle: Reload a module
language: javascript
tags: [node]
cover: tea-laptop-table
excerpt: Ever wanted to reload a module in Node.js? Here's how you can do it.
listed: true
dateModified: 2024-05-13
---
If you've ever tried to **reload a module** in Node.js, you might ha... | ---
title: Can I reload a module in Node.js?
shortTitle: Reload a module
language: javascript
tags: [node]
cover: tea-laptop-table
excerpt: Ever wanted to reload a module in Node.js? Here's how you can do it.
listed: true
dateModified: 2024-05-13
---
If you've ever tried to **reload a module** in Node.js, you might ha... | code_snippets | ||
15d0abc6-9386-4fe3-b320-52dfcfc50720 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-attributes.md | unknown | dc1cfb65-2c17-44db-8fcd-89902f407c08 | 0 | SemanticChunker@1.0.0 | b2c857c8131429269c23f1dff1530f9711fecd2317341b9dce71ac3a9ecdb066 | ---
title: Remove attributes from an HTML element with JavaScript
shortTitle: Remove attributes
language: javascript
tags: [browser]
cover: new-york
excerpt: A simple trick to remove one or more attributes from an HTML element.
listed: true
dateModified: 2023-10-21
---
Any attribute of an HTML element can be removed, ... | unknown | unknown | ---
title: Remove attributes from an HTML element with JavaScript
shortTitle: Remove attributes
language: javascript
tags: [browser]
cover: new-york
excerpt: A simple trick to remove one or more attributes from an HTML element.
listed: true
dateModified: 2023-10-21
---
Any attribute of an HTML element can be removed, ... | ---
title: Remove attributes from an HTML element with JavaScript
shortTitle: Remove attributes
language: javascript
tags: [browser]
cover: new-york
excerpt: A simple trick to remove one or more attributes from an HTML element.
listed: true
dateModified: 2023-10-21
---
Any attribute of an HTML element can be removed, ... | code_snippets | ||
1311ea0c-0e73-473f-9531-8ea43055d7a5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/relative-time-formatting.md | unknown | 798fa79c-d56f-48fc-9dda-5ef5707af889 | 4 | SemanticChunker@1.0.0 | 1c2e8b4121c283ae1b557342874de1d66f7815769c9647670f5cdbc366321fd7 | [Constructing a formatter > Formatting date differences]
```js
const dateDifferenceInYears = (a, b) => dateDifferenceInMonths(a, b) / 12;
const dateDifferenceInMonths = (a, b) =>
(b.getFullYear() - a.getFullYear()) * 12 + b.getMonth() - a.getMonth();
const dateDifferenceInWeeks = (a, b) => (b - a) / 604_800_000;
con... | unknown | unknown | [Constructing a formatter > Formatting date differences]
```js
const dateDifferenceInYears = (a, b) => dateDifferenceInMonths(a, b) / 12;
const dateDifferenceInMonths = (a, b) =>
(b.getFullYear() - a.getFullYear()) * 12 + b.getMonth() - a.getMonth();
const dateDifferenceInWeeks = (a, b) => (b - a) / 604_800_000;
con... | [Constructing a formatter > Formatting date differences]
```js
const dateDifferenceInYears = (a, b) => dateDifferenceInMonths(a, b) / 12;
const dateDifferenceInMonths = (a, b) =>
(b.getFullYear() - a.getFullYear()) * 12 + b.getMonth() - a.getMonth();
const dateDifferenceInWeeks = (a, b) => (b - a) / 604_800_000;
con... | code_snippets | ||
66d9ab2d-e2e0-4b5c-b49d-16f737014ecf | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/relative-time-formatting.md | unknown | 798fa79c-d56f-48fc-9dda-5ef5707af889 | 2 | SemanticChunker@1.0.0 | e9fa7872358b12e1a651f6c3bc0d3216bdf5a3ce782515e6272ce868e9a06c5b | [Constructing a formatter > Formatting relative time]
## Formatting relative time
Once we have a formatter, we can use it to **format relative time**. The formatter's `Intl.RelativeTimeFormat.prototype.format()` method takes two arguments: the **value** and the **unit**. The value is a **number** that represents the ... | unknown | unknown | [Constructing a formatter > Formatting relative time]
## Formatting relative time
Once we have a formatter, we can use it to **format relative time**. The formatter's `Intl.RelativeTimeFormat.prototype.format()` method takes two arguments: the **value** and the **unit**. The value is a **number** that represents the ... | [Constructing a formatter > Formatting relative time]
## Formatting relative time
Once we have a formatter, we can use it to **format relative time**. The formatter's `Intl.RelativeTimeFormat.prototype.format()` method takes two arguments: the **value** and the **unit**. The value is a **number** that represents the ... | code_snippets | ||
733d4afa-cf50-4af1-952f-450f9cc3dee1 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/relative-time-formatting.md | unknown | 798fa79c-d56f-48fc-9dda-5ef5707af889 | 3 | SemanticChunker@1.0.0 | 532895f36584d2583b6acf6032fb50cf7b813714520dbc72c8f4dfdf2a123773 | [Constructing a formatter > Formatting date differences]
## Formatting date differences
As we've seen in a [previous article](/js/s/date-difference), a little bit of math is all you need to find the **difference between two dates**. We can use this to calculate the difference between today and another date, pick the ... | unknown | unknown | [Constructing a formatter > Formatting date differences]
## Formatting date differences
As we've seen in a [previous article](/js/s/date-difference), a little bit of math is all you need to find the **difference between two dates**. We can use this to calculate the difference between today and another date, pick the ... | [Constructing a formatter > Formatting date differences]
## Formatting date differences
As we've seen in a [previous article](/js/s/date-difference), a little bit of math is all you need to find the **difference between two dates**. We can use this to calculate the difference between today and another date, pick the ... | code_snippets | ||
c35e5c98-98ce-4567-9b22-bea54f796feb | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/relative-time-formatting.md | unknown | 798fa79c-d56f-48fc-9dda-5ef5707af889 | 0 | SemanticChunker@1.0.0 | 0c4d8f1718ed8619beb71ef076b148037865f6d84a5113fc9f1baa20ed822d89 | ---
title: Formatting relative time in JavaScript
shortTitle: Relative time formatting
language: javascript
tags: [number,date]
cover: dog-waiting
excerpt: Did you know JavaScript has a built-in way to format relative time? It's called `Intl.RelativeTimeFormat` and it's awesome!
listed: true
dateModified: 2025-04-24
--... | unknown | unknown | ---
title: Formatting relative time in JavaScript
shortTitle: Relative time formatting
language: javascript
tags: [number,date]
cover: dog-waiting
excerpt: Did you know JavaScript has a built-in way to format relative time? It's called `Intl.RelativeTimeFormat` and it's awesome!
listed: true
dateModified: 2025-04-24
--... | ---
title: Formatting relative time in JavaScript
shortTitle: Relative time formatting
language: javascript
tags: [number,date]
cover: dog-waiting
excerpt: Did you know JavaScript has a built-in way to format relative time? It's called `Intl.RelativeTimeFormat` and it's awesome!
listed: true
dateModified: 2025-04-24
--... | code_snippets | ||
ce5df660-9c62-4528-a17f-d29d99462e73 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/relative-time-formatting.md | unknown | 798fa79c-d56f-48fc-9dda-5ef5707af889 | 5 | SemanticChunker@1.0.0 | 7620494b71f6ac1e5d603a2e1627f71f63aecc6abf44bf8355567ff979bce47a | [Constructing a formatter > Formatting date differences]
This is quite long, isn't it? And for good reason, too! While it seems easy to intuitively calculate the difference between two timestamps, once you get into the weeds of it, the complexity is much higher than you would expect. This one took me quite a little bi... | unknown | unknown | [Constructing a formatter > Formatting date differences]
This is quite long, isn't it? And for good reason, too! While it seems easy to intuitively calculate the difference between two timestamps, once you get into the weeds of it, the complexity is much higher than you would expect. This one took me quite a little bi... | [Constructing a formatter > Formatting date differences]
This is quite long, isn't it? And for good reason, too! While it seems easy to intuitively calculate the difference between two timestamps, once you get into the weeds of it, the complexity is much higher than you would expect. This one took me quite a little bi... | code_snippets | ||
e7be6aa8-e644-43c9-a829-f7251401226b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/relative-time-formatting.md | unknown | 798fa79c-d56f-48fc-9dda-5ef5707af889 | 6 | SemanticChunker@1.0.0 | ee06d0de9d90ca695e7f338ce0fd680fb32bfcbc631dddcd360a1fc96ff9ec6e | [Constructing a formatter > Conclusion]
## Conclusion
`Intl.RelativeTimeFormat` is a great addition to the JavaScript language. It makes formatting really easy, leaving you more space to focus on the hard parts: figuring out what unit to use and under which circumstances. Hopefully, you'll be able to take my code and... | unknown | unknown | [Constructing a formatter > Conclusion]
## Conclusion
`Intl.RelativeTimeFormat` is a great addition to the JavaScript language. It makes formatting really easy, leaving you more space to focus on the hard parts: figuring out what unit to use and under which circumstances. Hopefully, you'll be able to take my code and... | [Constructing a formatter > Conclusion]
## Conclusion
`Intl.RelativeTimeFormat` is a great addition to the JavaScript language. It makes formatting really easy, leaving you more space to focus on the hard parts: figuring out what unit to use and under which circumstances. Hopefully, you'll be able to take my code and... | code_snippets | ||
e9ab009c-e399-480a-83c9-499f02b5aeec | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/relative-time-formatting.md | unknown | 798fa79c-d56f-48fc-9dda-5ef5707af889 | 1 | SemanticChunker@1.0.0 | 1592d4b693b08eef3da60897a4cb04e4c9a05b69d83f657f5a61a795717c44bd | [Constructing a formatter]
## Constructing a formatter
The first step in this process is to create a new `Intl.RelativeTimeFormat` object. This object takes two arguments: the **locale** and an **options** object.
The locale is a string that specifies the locale (language & region or just language) to use for format... | unknown | unknown | [Constructing a formatter]
## Constructing a formatter
The first step in this process is to create a new `Intl.RelativeTimeFormat` object. This object takes two arguments: the **locale** and an **options** object.
The locale is a string that specifies the locale (language & region or just language) to use for format... | [Constructing a formatter]
## Constructing a formatter
The first step in this process is to create a new `Intl.RelativeTimeFormat` object. This object takes two arguments: the **locale** and an **options** object.
The locale is a string that specifies the locale (language & region or just language) to use for format... | code_snippets | ||
29972fb3-fde6-4f23-aa0f-bcfb2eb5d8fa | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/recursion.md | unknown | beab3c3a-e06b-4dc1-be67-e4cc486d2fa7 | 0 | SemanticChunker@1.0.0 | f60fd8f8bee4d6390e8e49147180b31723f2e8e0d1ab59e3b28a745c9f978544 | ---
title: What is recursion and when is it useful?
shortTitle: Recursion introduction
language: javascript
tags: [function,recursion]
cover: curve
excerpt: Recursion is a very important programming concept all developers should be familiar with.
listed: true
dateModified: 2022-01-23
journeyId: js/functional-programmin... | unknown | unknown | ---
title: What is recursion and when is it useful?
shortTitle: Recursion introduction
language: javascript
tags: [function,recursion]
cover: curve
excerpt: Recursion is a very important programming concept all developers should be familiar with.
listed: true
dateModified: 2022-01-23
journeyId: js/functional-programmin... | ---
title: What is recursion and when is it useful?
shortTitle: Recursion introduction
language: javascript
tags: [function,recursion]
cover: curve
excerpt: Recursion is a very important programming concept all developers should be familiar with.
listed: true
dateModified: 2022-01-23
journeyId: js/functional-programmin... | code_snippets | ||
334c9c91-8aa5-4d44-be3e-a21da4bc61f4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/regexp-cheatsheet.md | unknown | 05087611-47a5-4da4-bc7f-9483356ff70a | 1 | SemanticChunker@1.0.0 | 6b8816d00a54ede3eec5e23599ca820fd671ad413ff229287ee9e6f331b76b59 | [Anchors]
## Anchors
- `^`: start of the string or the start of a line in a multiline pattern
- `$`: end of the string or the end of a line in a multiline pattern
- `\b`: word boundary
- `\B`: not word boundary (opposite of `\b`)
> [!NOTE]
>
> Anchors are non-quantifiable (i.e. cannot be followed by a quantifier). | unknown | unknown | [Anchors]
## Anchors
- `^`: start of the string or the start of a line in a multiline pattern
- `$`: end of the string or the end of a line in a multiline pattern
- `\b`: word boundary
- `\B`: not word boundary (opposite of `\b`)
> [!NOTE]
>
> Anchors are non-quantifiable (i.e. cannot be followed by a quantifier). | [Anchors]
## Anchors
- `^`: start of the string or the start of a line in a multiline pattern
- `$`: end of the string or the end of a line in a multiline pattern
- `\b`: word boundary
- `\B`: not word boundary (opposite of `\b`)
> [!NOTE]
>
> Anchors are non-quantifiable (i.e. cannot be followed by a quantifier). | code_snippets | ||
4dd14d6a-13db-4224-9117-150686b4fcc8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/regexp-cheatsheet.md | unknown | 05087611-47a5-4da4-bc7f-9483356ff70a | 4 | SemanticChunker@1.0.0 | f591bf530ae298ea7cac2224874f52de2738e2a567668aa7b144df5b07212cc2 | [Anchors > Groups]
## Groups
- `(ab)`: match and capture everything enclosed (here exactly `ab`)
- `(a|b)`: match and capture either one character (here `a` or `b`)
- `(?:ab)`: match everything enclosed, without capturing | unknown | unknown | [Anchors > Groups]
## Groups
- `(ab)`: match and capture everything enclosed (here exactly `ab`)
- `(a|b)`: match and capture either one character (here `a` or `b`)
- `(?:ab)`: match everything enclosed, without capturing | [Anchors > Groups]
## Groups
- `(ab)`: match and capture everything enclosed (here exactly `ab`)
- `(a|b)`: match and capture either one character (here `a` or `b`)
- `(?:ab)`: match everything enclosed, without capturing | code_snippets | ||
a89b3f08-0fcf-436d-9908-65353b3164d6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/regexp-cheatsheet.md | unknown | 05087611-47a5-4da4-bc7f-9483356ff70a | 3 | SemanticChunker@1.0.0 | e14dfebbbf5a1dfde0dbc8d43330240a8ddc1120a83db37bbc0dd81ce6948569 | [Anchors > Quantifiers]
## Quantifiers
- `a?`: zero or one of `a` (equal to `a{0,1}`)
- `a*`: zero or more of `a` (equal to `a{0,}`)
- `a+`: one or more of `a` (equal to `a{1,}`)
- `a{3}`: exactly 3 of `a`
- `a{3,}`: 3 or more of `a`
- `a{3,5}`: between 3 and 5 of `a` (inclusive)
> [!NOTE]
>
> `a` is any valid quant... | unknown | unknown | [Anchors > Quantifiers]
## Quantifiers
- `a?`: zero or one of `a` (equal to `a{0,1}`)
- `a*`: zero or more of `a` (equal to `a{0,}`)
- `a+`: one or more of `a` (equal to `a{1,}`)
- `a{3}`: exactly 3 of `a`
- `a{3,}`: 3 or more of `a`
- `a{3,5}`: between 3 and 5 of `a` (inclusive)
> [!NOTE]
>
> `a` is any valid quant... | [Anchors > Quantifiers]
## Quantifiers
- `a?`: zero or one of `a` (equal to `a{0,1}`)
- `a*`: zero or more of `a` (equal to `a{0,}`)
- `a+`: one or more of `a` (equal to `a{1,}`)
- `a{3}`: exactly 3 of `a`
- `a{3,}`: 3 or more of `a`
- `a{3,5}`: between 3 and 5 of `a` (inclusive)
> [!NOTE]
>
> `a` is any valid quant... | code_snippets | ||
a8ebce2e-bfdf-481b-a5a0-3f7927f4caea | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/regexp-cheatsheet.md | unknown | 05087611-47a5-4da4-bc7f-9483356ff70a | 2 | SemanticChunker@1.0.0 | 12132d07b31830db93c4d68918aec62a2ae831042d418c0b26faf06b89f43c07 | [Anchors > Character sequences]
## Character sequences
- `.`: any character except line breaks
- `\w`: any word character
- `\W`: any non-word character (opposite of `\w`)
- `\s`: any whitespace character
- `\S`: any non-whitespace character (opposite of `\s`)
- `\d`: any digit character
- `\D`: any non-digit charact... | unknown | unknown | [Anchors > Character sequences]
## Character sequences
- `.`: any character except line breaks
- `\w`: any word character
- `\W`: any non-word character (opposite of `\w`)
- `\s`: any whitespace character
- `\S`: any non-whitespace character (opposite of `\s`)
- `\d`: any digit character
- `\D`: any non-digit charact... | [Anchors > Character sequences]
## Character sequences
- `.`: any character except line breaks
- `\w`: any word character
- `\W`: any non-word character (opposite of `\w`)
- `\s`: any whitespace character
- `\S`: any non-whitespace character (opposite of `\s`)
- `\d`: any digit character
- `\D`: any non-digit charact... | code_snippets | ||
de507dc0-4c8e-42b5-bb19-c2c952dd0bad | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/regexp-cheatsheet.md | unknown | 05087611-47a5-4da4-bc7f-9483356ff70a | 0 | SemanticChunker@1.0.0 | 3ca29c61fbe38c79bc28fa16494ba8a7aa41b1d241d707d015caa79f25dc5f56 | ---
title: Regular Expressions Cheat Sheet
language: javascript
tags: [string,regexp,cheatsheet]
cover: tools
excerpt: Regular expressions are a very useful tool. Save this cheatsheet for when you need to look up their syntax and speed up your development.
listed: true
dateModified: 2021-06-12
--- | unknown | unknown | ---
title: Regular Expressions Cheat Sheet
language: javascript
tags: [string,regexp,cheatsheet]
cover: tools
excerpt: Regular expressions are a very useful tool. Save this cheatsheet for when you need to look up their syntax and speed up your development.
listed: true
dateModified: 2021-06-12
--- | ---
title: Regular Expressions Cheat Sheet
language: javascript
tags: [string,regexp,cheatsheet]
cover: tools
excerpt: Regular expressions are a very useful tool. Save this cheatsheet for when you need to look up their syntax and speed up your development.
listed: true
dateModified: 2021-06-12
--- | code_snippets | ||
ecf1df34-9ae5-4dc9-861a-430593fbdaab | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/regexp-cheatsheet.md | unknown | 05087611-47a5-4da4-bc7f-9483356ff70a | 5 | SemanticChunker@1.0.0 | 363dc8ff9c0d9c31e891f772e023bfff4c5f9a1479b174f8eea9f3e61e7bfec5 | [Anchors > Flags]
## Flags
- `g`: Global
- `m`: Multiline
- `i`: Case insensitive
- `u`: Unicode
Note that this cheatsheet is meant only as a starting point and is by no means a complete guide to all the features and nuances of regular expressions.
@[Dive deeper](/js/s/6-regexp-tricks) | unknown | unknown | [Anchors > Flags]
## Flags
- `g`: Global
- `m`: Multiline
- `i`: Case insensitive
- `u`: Unicode
Note that this cheatsheet is meant only as a starting point and is by no means a complete guide to all the features and nuances of regular expressions.
@[Dive deeper](/js/s/6-regexp-tricks) | [Anchors > Flags]
## Flags
- `g`: Global
- `m`: Multiline
- `i`: Case insensitive
- `u`: Unicode
Note that this cheatsheet is meant only as a starting point and is by no means a complete guide to all the features and nuances of regular expressions.
@[Dive deeper](/js/s/6-regexp-tricks) | code_snippets | ||
03283a67-02ad-4508-9668-3a0634ef116f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/reload-page.md | unknown | 7d541d52-d2bb-4905-b7e6-18f274f72f79 | 0 | SemanticChunker@1.0.0 | bfa62869af32baf336be72b71b514c8fe0dd461d5ac2795c1d160b64383dca04 | ---
title: How can I use JavaScript to reload the page?
shortTitle: Reload page
language: javascript
tags: [browser]
cover: night-tram
excerpt: Need to reload the current page using JavaScript? Here's the best way to do it, as well as some alternatives.
listed: true
dateModified: 2023-05-14
--- | unknown | unknown | ---
title: How can I use JavaScript to reload the page?
shortTitle: Reload page
language: javascript
tags: [browser]
cover: night-tram
excerpt: Need to reload the current page using JavaScript? Here's the best way to do it, as well as some alternatives.
listed: true
dateModified: 2023-05-14
--- | ---
title: How can I use JavaScript to reload the page?
shortTitle: Reload page
language: javascript
tags: [browser]
cover: night-tram
excerpt: Need to reload the current page using JavaScript? Here's the best way to do it, as well as some alternatives.
listed: true
dateModified: 2023-05-14
--- | code_snippets | ||
53a72cbe-fc68-4279-8f41-16199e8d624d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/reload-page.md | unknown | 7d541d52-d2bb-4905-b7e6-18f274f72f79 | 2 | SemanticChunker@1.0.0 | fb9a374eee64b9c6cf37de59522c5112b9fd6e832123bac99ab2c4f79c237be2 | [The short answer > The slightly longer answer]
## The slightly longer answer
While `window.location.reload()` is the most common way to reload a page, there are some nuances that you might need to be aware of.
As stated already, compatibility shouldn't be an issue, so we're not going to delve into that. However, th... | unknown | unknown | [The short answer > The slightly longer answer]
## The slightly longer answer
While `window.location.reload()` is the most common way to reload a page, there are some nuances that you might need to be aware of.
As stated already, compatibility shouldn't be an issue, so we're not going to delve into that. However, th... | [The short answer > The slightly longer answer]
## The slightly longer answer
While `window.location.reload()` is the most common way to reload a page, there are some nuances that you might need to be aware of.
As stated already, compatibility shouldn't be an issue, so we're not going to delve into that. However, th... | code_snippets | ||
68249b11-eaca-46b2-902a-2b0c6a1af867 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/reload-page.md | unknown | 7d541d52-d2bb-4905-b7e6-18f274f72f79 | 1 | SemanticChunker@1.0.0 | b55a38c7ae42ac901c447fe0245750c746fa0f4f054af8841f4a497ec2c41167 | [The short answer]
## The short answer
Most often than not, `window.location.reload()` is all you need to reload the current page. This method behaves exactly like the **browser's reload button**, using the same cache rules and everything.
```js
// Reload the page
window.location.reload();
``` | unknown | unknown | [The short answer]
## The short answer
Most often than not, `window.location.reload()` is all you need to reload the current page. This method behaves exactly like the **browser's reload button**, using the same cache rules and everything.
```js
// Reload the page
window.location.reload();
``` | [The short answer]
## The short answer
Most often than not, `window.location.reload()` is all you need to reload the current page. This method behaves exactly like the **browser's reload button**, using the same cache rules and everything.
```js
// Reload the page
window.location.reload();
``` | code_snippets | ||
5fde9c82-61b9-485d-90ad-8bd0697ab6e9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/recursion-performance-optimization.md | unknown | 7b0bb648-1639-477b-94a0-76e11d0403b9 | 0 | SemanticChunker@1.0.0 | 0dda51a54a7416fe17e66933f1c81bbcf40913969761855e89db33e62f966d4e | ---
title: Optimizing recursive functions in JavaScript
shortTitle: Recursive functions optimization
language: javascript
tags: [recursion,performance]
cover: case-study
excerpt: Recursive code tends to be inefficient or in need of optimization. Learn a couple of tricks we use to speed up our recursive functions.
liste... | unknown | unknown | ---
title: Optimizing recursive functions in JavaScript
shortTitle: Recursive functions optimization
language: javascript
tags: [recursion,performance]
cover: case-study
excerpt: Recursive code tends to be inefficient or in need of optimization. Learn a couple of tricks we use to speed up our recursive functions.
liste... | ---
title: Optimizing recursive functions in JavaScript
shortTitle: Recursive functions optimization
language: javascript
tags: [recursion,performance]
cover: case-study
excerpt: Recursive code tends to be inefficient or in need of optimization. Learn a couple of tricks we use to speed up our recursive functions.
liste... | code_snippets | ||
b36712b2-3827-4628-8a52-26dad0fc896d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/recursion-performance-optimization.md | unknown | 7b0bb648-1639-477b-94a0-76e11d0403b9 | 1 | SemanticChunker@1.0.0 | c3874daeb75da3e7ebcf4e2e1d47c17341f13b2ce9c71d92928e5ba5f9b09d85 | [Recursive functions]
## Recursive functions
Recursion is a programming technique where the final solution is computed by breaking down the problem into smaller instances of the same problem and computing the solution for each one. The most common implementation is a function that calls itself, reducing the problem e... | unknown | unknown | [Recursive functions]
## Recursive functions
Recursion is a programming technique where the final solution is computed by breaking down the problem into smaller instances of the same problem and computing the solution for each one. The most common implementation is a function that calls itself, reducing the problem e... | [Recursive functions]
## Recursive functions
Recursion is a programming technique where the final solution is computed by breaking down the problem into smaller instances of the same problem and computing the solution for each one. The most common implementation is a function that calls itself, reducing the problem e... | code_snippets | ||
e1ea4616-9160-4fba-aeff-1f4c479c5397 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/recursion-performance-optimization.md | unknown | 7b0bb648-1639-477b-94a0-76e11d0403b9 | 3 | SemanticChunker@1.0.0 | 71f602f97146116460934f926f99fd13fd716ac12fe2bb4c31b2060a4886fcb6 | [Recursive functions > Using iteration]
## Using iteration
The second and final trick stems from the very definition of recursive programming turned on its head. If we can solve a smaller instance of the problem and use it for the solution of a larger instance of the problem, it should be possible to work iteratively... | unknown | unknown | [Recursive functions > Using iteration]
## Using iteration
The second and final trick stems from the very definition of recursive programming turned on its head. If we can solve a smaller instance of the problem and use it for the solution of a larger instance of the problem, it should be possible to work iteratively... | [Recursive functions > Using iteration]
## Using iteration
The second and final trick stems from the very definition of recursive programming turned on its head. If we can solve a smaller instance of the problem and use it for the solution of a larger instance of the problem, it should be possible to work iteratively... | code_snippets | ||
fb75ca27-cbc7-4832-b19e-6fe5750b5225 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/recursion-performance-optimization.md | unknown | 7b0bb648-1639-477b-94a0-76e11d0403b9 | 2 | SemanticChunker@1.0.0 | 539a1cf518f4a8155b82800516559a21ffbdfdbe85d4c9f4c7ee377ffd3e658b | [Recursive functions > Calculation memoization]
## Calculation memoization
The solution to this problem, and the first trick that you can use to speed up recursive functions, is to use memoization. We already published [a great article on memoization](/js/s/memoization/) a little while back, so be sure to check it ou... | unknown | unknown | [Recursive functions > Calculation memoization]
## Calculation memoization
The solution to this problem, and the first trick that you can use to speed up recursive functions, is to use memoization. We already published [a great article on memoization](/js/s/memoization/) a little while back, so be sure to check it ou... | [Recursive functions > Calculation memoization]
## Calculation memoization
The solution to this problem, and the first trick that you can use to speed up recursive functions, is to use memoization. We already published [a great article on memoization](/js/s/memoization/) a little while back, so be sure to check it ou... | code_snippets | ||
b8479ce3-a1f9-42e5-bd10-cb302fb5b677 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-accents.md | unknown | ce08c588-5154-459e-9439-b68577643dcd | 0 | SemanticChunker@1.0.0 | d53ef45bd1ab290b02d88ca3bf9bced961b90faa5d81f6cfeb1968f16c5dee2d | ---
title: Remove accents from a JavaScript string
shortTitle: Remove accents
language: javascript
tags: [string,regexp]
cover: pink-flowers
excerpt: Learn how to remove accents from a string in JavaScript, quickly and efficiently.
listed: true
dateModified: 2024-02-07
---
Oftentimes you might need to **remove accents... | unknown | unknown | ---
title: Remove accents from a JavaScript string
shortTitle: Remove accents
language: javascript
tags: [string,regexp]
cover: pink-flowers
excerpt: Learn how to remove accents from a string in JavaScript, quickly and efficiently.
listed: true
dateModified: 2024-02-07
---
Oftentimes you might need to **remove accents... | ---
title: Remove accents from a JavaScript string
shortTitle: Remove accents
language: javascript
tags: [string,regexp]
cover: pink-flowers
excerpt: Learn how to remove accents from a string in JavaScript, quickly and efficiently.
listed: true
dateModified: 2024-02-07
---
Oftentimes you might need to **remove accents... | code_snippets | ||
b72d7295-7759-4802-a0fb-1e160132c067 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/record-animation-frames.md | unknown | 4bf56f40-7df6-46ed-9cd6-5a1f409944dd | 0 | SemanticChunker@1.0.0 | 31bb26072c2ebdf94e3dcc60721e64190dce5342da78028986b8671520047944 | ---
title: Run a callback on each animation frame with JavaScript
shortTitle: Record animation frames
language: javascript
tags: [browser,recursion]
cover: mac-and-coffee
excerpt: Ever wanted to run a function on each animation frame? This article shows you how to do it using `Window.requestAnimationFrame()`.
listed: t... | unknown | unknown | ---
title: Run a callback on each animation frame with JavaScript
shortTitle: Record animation frames
language: javascript
tags: [browser,recursion]
cover: mac-and-coffee
excerpt: Ever wanted to run a function on each animation frame? This article shows you how to do it using `Window.requestAnimationFrame()`.
listed: t... | ---
title: Run a callback on each animation frame with JavaScript
shortTitle: Record animation frames
language: javascript
tags: [browser,recursion]
cover: mac-and-coffee
excerpt: Ever wanted to run a function on each animation frame? This article shows you how to do it using `Window.requestAnimationFrame()`.
listed: t... | code_snippets | ||
c00898e9-4ee1-4b90-984d-8584b6ca625e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/record-animation-frames.md | unknown | 4bf56f40-7df6-46ed-9cd6-5a1f409944dd | 1 | SemanticChunker@1.0.0 | 3f6d8a0d4692f1c9204c9f7c9b4fe56567e3e52be44237096a6e77230b2fb9b9 | Finally, if the `autoStart` argument is `true`, we call `start` when the function is invoked. If it is set to `false`, we require the user to call `start` manually.
```js
const recordAnimationFrames = (callback, autoStart = true) => {
let running = false, raf;
const stop = () => {
if (!running) return;
running = ... | unknown | unknown | Finally, if the `autoStart` argument is `true`, we call `start` when the function is invoked. If it is set to `false`, we require the user to call `start` manually.
```js
const recordAnimationFrames = (callback, autoStart = true) => {
let running = false, raf;
const stop = () => {
if (!running) return;
running = ... | Finally, if the `autoStart` argument is `true`, we call `start` when the function is invoked. If it is set to `false`, we require the user to call `start` manually.
```js
const recordAnimationFrames = (callback, autoStart = true) => {
let running = false, raf;
const stop = () => {
if (!running) return;
running = ... | code_snippets | ||
0fe2f364-37e2-4698-b83e-6cf110e97885 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/read-file-lines.md | unknown | eaab7fe7-1bb3-4ca7-9505-a4bba6bf2f1b | 1 | SemanticChunker@1.0.0 | 1ef5321bdc2e5eabdd5732377c85538433ed8001c50bbe280a44963f26c83510 | [Read a text file]
## Read a text file
**Reading** text files can be accomplished either using `fs.readFileSync()` or `fs.readFile()`. The former is **synchronous** and blocks the event loop, while the latter is **asynchronous** and non-blocking, returning a `Promise`.
Both methods return a `Buffer` object, which ca... | unknown | unknown | [Read a text file]
## Read a text file
**Reading** text files can be accomplished either using `fs.readFileSync()` or `fs.readFile()`. The former is **synchronous** and blocks the event loop, while the latter is **asynchronous** and non-blocking, returning a `Promise`.
Both methods return a `Buffer` object, which ca... | [Read a text file]
## Read a text file
**Reading** text files can be accomplished either using `fs.readFileSync()` or `fs.readFile()`. The former is **synchronous** and blocks the event loop, while the latter is **asynchronous** and non-blocking, returning a `Promise`.
Both methods return a `Buffer` object, which ca... | code_snippets | ||
3734b998-fb47-4165-9f12-fac10ae45411 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/read-file-lines.md | unknown | eaab7fe7-1bb3-4ca7-9505-a4bba6bf2f1b | 0 | SemanticChunker@1.0.0 | 798c266eb16fc895107cb13d805bf24a767dd322fa7ef72317bfe9f80b729e78 | ---
title: Read a file and return an array of lines
shortTitle: Read file lines
language: javascript
tags: [node]
cover: solitude-beach
excerpt: Parse a text file and return an array of lines, synchronously or asynchronously, using Node.js.
listed: true
dateModified: 2024-05-20
---
Parsing **text files** is one of the... | unknown | unknown | ---
title: Read a file and return an array of lines
shortTitle: Read file lines
language: javascript
tags: [node]
cover: solitude-beach
excerpt: Parse a text file and return an array of lines, synchronously or asynchronously, using Node.js.
listed: true
dateModified: 2024-05-20
---
Parsing **text files** is one of the... | ---
title: Read a file and return an array of lines
shortTitle: Read file lines
language: javascript
tags: [node]
cover: solitude-beach
excerpt: Parse a text file and return an array of lines, synchronously or asynchronously, using Node.js.
listed: true
dateModified: 2024-05-20
---
Parsing **text files** is one of the... | code_snippets | ||
4913d728-afb9-4647-a8d5-db877c287402 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/read-file-lines.md | unknown | eaab7fe7-1bb3-4ca7-9505-a4bba6bf2f1b | 2 | SemanticChunker@1.0.0 | f21828475a0f7260f56c885aa9228bc09c032b98f995c607562e7cb56a60ec9b | [Read a text file > Read file and convert to an array of lines]
## Read file and convert to an array of lines
To convert the contents of a file to an array of lines, you can use `String.prototype.split()` to **split the string by the newline character** (`\n`).
```js
const fileContents = 'line1\nline2\nline3\n';
fi... | unknown | unknown | [Read a text file > Read file and convert to an array of lines]
## Read file and convert to an array of lines
To convert the contents of a file to an array of lines, you can use `String.prototype.split()` to **split the string by the newline character** (`\n`).
```js
const fileContents = 'line1\nline2\nline3\n';
fi... | [Read a text file > Read file and convert to an array of lines]
## Read file and convert to an array of lines
To convert the contents of a file to an array of lines, you can use `String.prototype.split()` to **split the string by the newline character** (`\n`).
```js
const fileContents = 'line1\nline2\nline3\n';
fi... | code_snippets | ||
c7d1dbe8-0677-4921-9257-3c671927b4c0 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/read-file-lines.md | unknown | eaab7fe7-1bb3-4ca7-9505-a4bba6bf2f1b | 4 | SemanticChunker@1.0.0 | cb6a7500aa030b9ec16d33a725f5c41b0c117c7861380d6515497e575e07f1cd | [Read file and convert to an array of lines > Read file lines synchronously]
### Read file lines synchronously
If you prefer synchronous code, you can read the file **synchronously** and convert it to an array of lines. The resulting array can be used directly.
```js
import { readFileSync } from 'fs';
const readFil... | unknown | unknown | [Read file and convert to an array of lines > Read file lines synchronously]
### Read file lines synchronously
If you prefer synchronous code, you can read the file **synchronously** and convert it to an array of lines. The resulting array can be used directly.
```js
import { readFileSync } from 'fs';
const readFil... | [Read file and convert to an array of lines > Read file lines synchronously]
### Read file lines synchronously
If you prefer synchronous code, you can read the file **synchronously** and convert it to an array of lines. The resulting array can be used directly.
```js
import { readFileSync } from 'fs';
const readFil... | code_snippets | ||
fdc7dffc-61d4-46d2-b735-670eeeed54ef | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/read-file-lines.md | unknown | eaab7fe7-1bb3-4ca7-9505-a4bba6bf2f1b | 3 | SemanticChunker@1.0.0 | 2f6ddd43cd2ff429fce866c562903e478a911e8df47d105a0983f7fc65b6a54b | [Read file and convert to an array of lines > Read file lines asynchronously]
### Read file lines asynchronously
Putting the pieces together, you can read a file **asynchronously** and return an array of lines. Make sure to handle the resulting `Promise` accordingly, using `await` or `Promise.prototype.then()`.
```j... | unknown | unknown | [Read file and convert to an array of lines > Read file lines asynchronously]
### Read file lines asynchronously
Putting the pieces together, you can read a file **asynchronously** and return an array of lines. Make sure to handle the resulting `Promise` accordingly, using `await` or `Promise.prototype.then()`.
```j... | [Read file and convert to an array of lines > Read file lines asynchronously]
### Read file lines asynchronously
Putting the pieces together, you can read a file **asynchronously** and return an array of lines. Make sure to handle the resulting `Promise` accordingly, using `await` or `Promise.prototype.then()`.
```j... | code_snippets | ||
ba1c91cc-d518-42c0-b068-d8b760433c2f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-matching-array-elements.md | unknown | e9fcf3b7-9c6e-4e18-b840-e965fefbd2fb | 2 | SemanticChunker@1.0.0 | 602b4af9715c4f093279d465deafca159472e24852424d1e9f381b435b8bec80 | [Inverting the condition > Mutating the array]
## Mutating the array
While mutating the array is often undesirable, it's worth mentioning that there's a way to mutate the array directly by using `Array.prototype.reduce()`. All you have to do is **find the matching elements** using `Array.prototype.filter()` and then ... | unknown | unknown | [Inverting the condition > Mutating the array]
## Mutating the array
While mutating the array is often undesirable, it's worth mentioning that there's a way to mutate the array directly by using `Array.prototype.reduce()`. All you have to do is **find the matching elements** using `Array.prototype.filter()` and then ... | [Inverting the condition > Mutating the array]
## Mutating the array
While mutating the array is often undesirable, it's worth mentioning that there's a way to mutate the array directly by using `Array.prototype.reduce()`. All you have to do is **find the matching elements** using `Array.prototype.filter()` and then ... | code_snippets | ||
e6b215a7-770a-4de8-9200-2cef5f17d97d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-matching-array-elements.md | unknown | e9fcf3b7-9c6e-4e18-b840-e965fefbd2fb | 0 | SemanticChunker@1.0.0 | 0842fb5dec77c2ddb5e750182610a60d919922e1f6a8a92343107c66fc140881 | ---
title: Remove matching elements from a JavaScript array
shortTitle: Remove matching elements from array
language: javascript
tags: [array]
cover: highlands
excerpt: Given a predicate function, remove elements from an array that match the given condition.
listed: true
dateModified: 2024-03-23
---
`Array.prototype.f... | unknown | unknown | ---
title: Remove matching elements from a JavaScript array
shortTitle: Remove matching elements from array
language: javascript
tags: [array]
cover: highlands
excerpt: Given a predicate function, remove elements from an array that match the given condition.
listed: true
dateModified: 2024-03-23
---
`Array.prototype.f... | ---
title: Remove matching elements from a JavaScript array
shortTitle: Remove matching elements from array
language: javascript
tags: [array]
cover: highlands
excerpt: Given a predicate function, remove elements from an array that match the given condition.
listed: true
dateModified: 2024-03-23
---
`Array.prototype.f... | code_snippets | ||
f7d31d20-0584-4888-bba6-e4db9b2e01cc | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-matching-array-elements.md | unknown | e9fcf3b7-9c6e-4e18-b840-e965fefbd2fb | 1 | SemanticChunker@1.0.0 | 44aa39fcf69665875a13a01c2c00390d38fba3818c3d49d1df153dc67de2a9db | [Inverting the condition]
## Inverting the condition
The simplest way to remove elements from an array that match a condition is to **invert the condition**. For example, if you want to remove all even numbers from an array, you can filter out all odd numbers instead.
In order to do so, you can simply **negate** the... | unknown | unknown | [Inverting the condition]
## Inverting the condition
The simplest way to remove elements from an array that match a condition is to **invert the condition**. For example, if you want to remove all even numbers from an array, you can filter out all odd numbers instead.
In order to do so, you can simply **negate** the... | [Inverting the condition]
## Inverting the condition
The simplest way to remove elements from an array that match a condition is to **invert the condition**. For example, if you want to remove all even numbers from an array, you can filter out all odd numbers instead.
In order to do so, you can simply **negate** the... | code_snippets | ||
1073f7c6-2458-497a-b4f4-893d9acdf12f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/render-dom-element.md | unknown | d0494a06-cb65-4b29-99df-e99aaf47afdf | 1 | SemanticChunker@1.0.0 | 896854aa546868810d105bc19eceb92f321fa9143f1693692c786dc778d4e22c | [Representing a DOM tree]
## Representing a DOM tree
In order to render a **DOM tree** in a specified container, you can create a function that takes an object representing the DOM tree and the container element. This function will **recursively** create and append DOM elements based on the given tree. But before we ... | unknown | unknown | [Representing a DOM tree]
## Representing a DOM tree
In order to render a **DOM tree** in a specified container, you can create a function that takes an object representing the DOM tree and the container element. This function will **recursively** create and append DOM elements based on the given tree. But before we ... | [Representing a DOM tree]
## Representing a DOM tree
In order to render a **DOM tree** in a specified container, you can create a function that takes an object representing the DOM tree and the container element. This function will **recursively** create and append DOM elements based on the given tree. But before we ... | code_snippets | ||
af0cb00c-2aea-4b52-8605-99f759edddd8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/render-dom-element.md | unknown | d0494a06-cb65-4b29-99df-e99aaf47afdf | 2 | SemanticChunker@1.0.0 | 204752bf59661e0b74d251e4cae23d67bf6571f7ea0a90819a1d5f733c9153e6 | [Representing a DOM tree > Rendering the DOM tree]
## Rendering the DOM tree
Having a robust representation of the DOM tree, we can now create the function that renders the given tree in the specified container. The function will destructure the first argument into `type` and `props`, and use `type` to determine if t... | unknown | unknown | [Representing a DOM tree > Rendering the DOM tree]
## Rendering the DOM tree
Having a robust representation of the DOM tree, we can now create the function that renders the given tree in the specified container. The function will destructure the first argument into `type` and `props`, and use `type` to determine if t... | [Representing a DOM tree > Rendering the DOM tree]
## Rendering the DOM tree
Having a robust representation of the DOM tree, we can now create the function that renders the given tree in the specified container. The function will destructure the first argument into `type` and `props`, and use `type` to determine if t... | code_snippets | ||
c67ddd92-4f7e-4f74-ae2b-cb692b5df967 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/render-dom-element.md | unknown | d0494a06-cb65-4b29-99df-e99aaf47afdf | 0 | SemanticChunker@1.0.0 | 1d633226b005612d3776cfad427a2cb891422370336849b9197bc7bd1fd1f08b | ---
title: Render DOM elements with JavaScript
shortTitle: Render DOM elements
language: javascript
tags: [browser,recursion]
cover: standing-stones
excerpt: Ever wondered how React's rendering works? Here's a simple JavaScript function that renders a DOM tree in a specified container.
listed: true
dateModified: 2024-0... | unknown | unknown | ---
title: Render DOM elements with JavaScript
shortTitle: Render DOM elements
language: javascript
tags: [browser,recursion]
cover: standing-stones
excerpt: Ever wondered how React's rendering works? Here's a simple JavaScript function that renders a DOM tree in a specified container.
listed: true
dateModified: 2024-0... | ---
title: Render DOM elements with JavaScript
shortTitle: Render DOM elements
language: javascript
tags: [browser,recursion]
cover: standing-stones
excerpt: Ever wondered how React's rendering works? Here's a simple JavaScript function that renders a DOM tree in a specified container.
listed: true
dateModified: 2024-0... | code_snippets | ||
d2b2f092-8629-46f9-a75e-0e2c8ee5323f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/render-dom-element.md | unknown | d0494a06-cb65-4b29-99df-e99aaf47afdf | 3 | SemanticChunker@1.0.0 | 9d6beb10be37c5acc17abe13ac1f264ad4f3f79309ef1f90dbd4b1ce5dc2f25f | [Representing a DOM tree > Rendering the DOM tree]
```js
const renderElement = ({ type, props = {} }, container) => {
const isTextElement = !type;
const element = isTextElement
? document.createTextNode('')
: document.createElement(type);
const isListener = p => p.startsWith('on');
const isAttribute = p => !isL... | unknown | unknown | [Representing a DOM tree > Rendering the DOM tree]
```js
const renderElement = ({ type, props = {} }, container) => {
const isTextElement = !type;
const element = isTextElement
? document.createTextNode('')
: document.createElement(type);
const isListener = p => p.startsWith('on');
const isAttribute = p => !isL... | [Representing a DOM tree > Rendering the DOM tree]
```js
const renderElement = ({ type, props = {} }, container) => {
const isTextElement = !type;
const element = isTextElement
? document.createTextNode('')
: document.createElement(type);
const isListener = p => p.startsWith('on');
const isAttribute = p => !isL... | code_snippets | ||
03490c21-d914-4ec6-8956-2a1211bba4b5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-first-last-n-array-elements.md | unknown | 141c95a4-bff0-41d7-b027-9166826b472e | 6 | SemanticChunker@1.0.0 | 5228be82fc9f55bc4c9c662df5bd3fa162bc2092be3faf9fadf4fafebe3879d0 | [Removing elements based on a condition > Remove array elements from the beginning based on a condition]
### Remove array elements from the beginning based on a condition
Before using `Array.prototype.slice()`, we first need to locate the first element matching the predicate function. This can be done using `Array.pr... | unknown | unknown | [Removing elements based on a condition > Remove array elements from the beginning based on a condition]
### Remove array elements from the beginning based on a condition
Before using `Array.prototype.slice()`, we first need to locate the first element matching the predicate function. This can be done using `Array.pr... | [Removing elements based on a condition > Remove array elements from the beginning based on a condition]
### Remove array elements from the beginning based on a condition
Before using `Array.prototype.slice()`, we first need to locate the first element matching the predicate function. This can be done using `Array.pr... | code_snippets | ||
1837c86f-376b-4442-9adb-7d89b86e47b6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-first-last-n-array-elements.md | unknown | 141c95a4-bff0-41d7-b027-9166826b472e | 4 | SemanticChunker@1.0.0 | 523bdd606eb98ecd4d597b7e68196acd5a175147e8656d3f40eabfc96ec1e8e3 | [Removing multiple elements > Remove array elements from the end]
### Remove array elements from the end
Conversely, in order to remove `n` elements from the end of an array, you can use `Array.prototype.slice()` with a start index of `0` and a negative end index. This will return a new array with the last `n` elemen... | unknown | unknown | [Removing multiple elements > Remove array elements from the end]
### Remove array elements from the end
Conversely, in order to remove `n` elements from the end of an array, you can use `Array.prototype.slice()` with a start index of `0` and a negative end index. This will return a new array with the last `n` elemen... | [Removing multiple elements > Remove array elements from the end]
### Remove array elements from the end
Conversely, in order to remove `n` elements from the end of an array, you can use `Array.prototype.slice()` with a start index of `0` and a negative end index. This will return a new array with the last `n` elemen... | code_snippets | ||
221a5f25-b5a3-4b39-aee5-49c4f720ed38 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-first-last-n-array-elements.md | unknown | 141c95a4-bff0-41d7-b027-9166826b472e | 0 | SemanticChunker@1.0.0 | 6a97a9aacab80a12f92729601c39b6e9584ea88b8c4908a5bf4c13f003c20325 | ---
title: Remove the first or last n elements from a JavaScript array
shortTitle: Remove first or last n array elements
language: javascript
tags: [array]
cover: metropolitan-window
excerpt: Master JavaScript array element removal with these simple techniques.
listed: true
dateModified: 2023-12-24
---
As discussed pr... | unknown | unknown | ---
title: Remove the first or last n elements from a JavaScript array
shortTitle: Remove first or last n array elements
language: javascript
tags: [array]
cover: metropolitan-window
excerpt: Master JavaScript array element removal with these simple techniques.
listed: true
dateModified: 2023-12-24
---
As discussed pr... | ---
title: Remove the first or last n elements from a JavaScript array
shortTitle: Remove first or last n array elements
language: javascript
tags: [array]
cover: metropolitan-window
excerpt: Master JavaScript array element removal with these simple techniques.
listed: true
dateModified: 2023-12-24
---
As discussed pr... | code_snippets | ||
334c6088-7fd4-4d32-97c1-f07ff87606cd | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-first-last-n-array-elements.md | unknown | 141c95a4-bff0-41d7-b027-9166826b472e | 7 | SemanticChunker@1.0.0 | 728ebd3f82f1f2cfca82a44f3f721914b677a37c47135a6da22910bdc238a9d7 | [Removing elements based on a condition > Remove array elements from the end based on a condition]
### Remove array elements from the end based on a condition
Similarly, we can remove elements from the end of an array based on a condition. This time around, we'll use `Array.prototype.findLastIndex()` to locate the la... | unknown | unknown | [Removing elements based on a condition > Remove array elements from the end based on a condition]
### Remove array elements from the end based on a condition
Similarly, we can remove elements from the end of an array based on a condition. This time around, we'll use `Array.prototype.findLastIndex()` to locate the la... | [Removing elements based on a condition > Remove array elements from the end based on a condition]
### Remove array elements from the end based on a condition
Similarly, we can remove elements from the end of an array based on a condition. This time around, we'll use `Array.prototype.findLastIndex()` to locate the la... | code_snippets | ||
4c1da5df-f5fa-4ed1-936c-b562e10e6938 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-first-last-n-array-elements.md | unknown | 141c95a4-bff0-41d7-b027-9166826b472e | 1 | SemanticChunker@1.0.0 | 902be70dda6dab5e69ce065a620dc2df4890d9e4501c36642a4a2b6d339851aa | [Mutative methods]
## Mutative methods
`Array.prototype.shift()` and `Array.prototype.pop()` are the two **mutative methods** available for removing a **single element** from the beginning or end of an array, respectively. Both methods mutate the original array and **return the removed element**.
```js
const arr = [... | unknown | unknown | [Mutative methods]
## Mutative methods
`Array.prototype.shift()` and `Array.prototype.pop()` are the two **mutative methods** available for removing a **single element** from the beginning or end of an array, respectively. Both methods mutate the original array and **return the removed element**.
```js
const arr = [... | [Mutative methods]
## Mutative methods
`Array.prototype.shift()` and `Array.prototype.pop()` are the two **mutative methods** available for removing a **single element** from the beginning or end of an array, respectively. Both methods mutate the original array and **return the removed element**.
```js
const arr = [... | code_snippets | ||
5f4257d3-754e-46c7-87bd-58127be218f2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-first-last-n-array-elements.md | unknown | 141c95a4-bff0-41d7-b027-9166826b472e | 5 | SemanticChunker@1.0.0 | 5854c54d7038628544b73773caa658e216a3fc4b962fe681e8213699496a921e | [Mutative methods > Removing elements based on a condition]
## Removing elements based on a condition
A more advanced use-case is **removing elements from an array based on a condition**. While `Array.prototype.filter()` is designed to do just that, it falls short when you want to remove all elements encountered unti... | unknown | unknown | [Mutative methods > Removing elements based on a condition]
## Removing elements based on a condition
A more advanced use-case is **removing elements from an array based on a condition**. While `Array.prototype.filter()` is designed to do just that, it falls short when you want to remove all elements encountered unti... | [Mutative methods > Removing elements based on a condition]
## Removing elements based on a condition
A more advanced use-case is **removing elements from an array based on a condition**. While `Array.prototype.filter()` is designed to do just that, it falls short when you want to remove all elements encountered unti... | code_snippets | ||
6f03b0a2-6cf5-4938-85d1-1158237927b6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-first-last-n-array-elements.md | unknown | 141c95a4-bff0-41d7-b027-9166826b472e | 2 | SemanticChunker@1.0.0 | 70c09e08903fb4a5e7c33e951c9275a5f07c3ab189c52da6184b90f3d8425b35 | [Mutative methods > Removing multiple elements]
## Removing multiple elements
If you need to remove multiple elements from the beginning or end of an array, you can use `Array.prototype.splice()` or `Array.prototype.slice()`. The main difference between the two is that `Array.prototype.splice()` **mutates the origina... | unknown | unknown | [Mutative methods > Removing multiple elements]
## Removing multiple elements
If you need to remove multiple elements from the beginning or end of an array, you can use `Array.prototype.splice()` or `Array.prototype.slice()`. The main difference between the two is that `Array.prototype.splice()` **mutates the origina... | [Mutative methods > Removing multiple elements]
## Removing multiple elements
If you need to remove multiple elements from the beginning or end of an array, you can use `Array.prototype.splice()` or `Array.prototype.slice()`. The main difference between the two is that `Array.prototype.splice()` **mutates the origina... | code_snippets | ||
778daab7-5374-434f-b7fa-1b8d418f8e5e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-first-last-n-array-elements.md | unknown | 141c95a4-bff0-41d7-b027-9166826b472e | 3 | SemanticChunker@1.0.0 | b16dd6841ba6e9fd106e52dbc56aaac9b9b354069824fded38368ff5f275df24 | [Removing multiple elements > Remove array elements from the beginning]
### Remove array elements from the beginning
In order to remove `n` elements from the beginning of an array, you can use `Array.prototype.slice()` with a positive start index and no end index. This will return a new array with the first `n` eleme... | unknown | unknown | [Removing multiple elements > Remove array elements from the beginning]
### Remove array elements from the beginning
In order to remove `n` elements from the beginning of an array, you can use `Array.prototype.slice()` with a positive start index and no end index. This will return a new array with the first `n` eleme... | [Removing multiple elements > Remove array elements from the beginning]
### Remove array elements from the beginning
In order to remove `n` elements from the beginning of an array, you can use `Array.prototype.slice()` with a positive start index and no end index. This will return a new array with the first `n` eleme... | code_snippets | ||
0c28627c-0196-4d83-abe1-1c06b5a80163 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-object-property.md | unknown | 37d5b5ed-bd82-4f21-8a2c-c4ead4cfcb01 | 1 | SemanticChunker@1.0.0 | 97c6b776d30ecd028c88a3ade1cd7705d71ada03535a35336584002a49dcdbb7 | [Set the property to undefined]
## Set the property to undefined
Setting a property to `undefined` isn't generally optimal, as the property itself will still be present in the object, albeit `undefined`. It also mutates the original object, which might be undesired. You might want to use this in cases where you check... | unknown | unknown | [Set the property to undefined]
## Set the property to undefined
Setting a property to `undefined` isn't generally optimal, as the property itself will still be present in the object, albeit `undefined`. It also mutates the original object, which might be undesired. You might want to use this in cases where you check... | [Set the property to undefined]
## Set the property to undefined
Setting a property to `undefined` isn't generally optimal, as the property itself will still be present in the object, albeit `undefined`. It also mutates the original object, which might be undesired. You might want to use this in cases where you check... | code_snippets | ||
0dd18c0c-4117-496a-94c0-fd8e4eecfcfd | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-object-property.md | unknown | 37d5b5ed-bd82-4f21-8a2c-c4ead4cfcb01 | 2 | SemanticChunker@1.0.0 | 4f0f3cda09554a9af89fba5101c22f26ea2ed2b94ea38ed269f7d076eb4e561c | [Set the property to undefined > Use the delete operator]
## Use the delete operator
The `delete` operator is technically the correct way to remove a property from a JavaScript object. Unlike the previous option, `delete` will completely remove the property from the object, but it will still cause a mutation.
```js
... | unknown | unknown | [Set the property to undefined > Use the delete operator]
## Use the delete operator
The `delete` operator is technically the correct way to remove a property from a JavaScript object. Unlike the previous option, `delete` will completely remove the property from the object, but it will still cause a mutation.
```js
... | [Set the property to undefined > Use the delete operator]
## Use the delete operator
The `delete` operator is technically the correct way to remove a property from a JavaScript object. Unlike the previous option, `delete` will completely remove the property from the object, but it will still cause a mutation.
```js
... | code_snippets | ||
57bdbb77-ef30-4722-8708-d280c0a5e6ee | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-object-property.md | unknown | 37d5b5ed-bd82-4f21-8a2c-c4ead4cfcb01 | 3 | SemanticChunker@1.0.0 | fb571b6519fc08a66d703923cb3ee99a2fc96864c4417cb962728f658272cd5c | [Set the property to undefined > Use object destructuring]
## Use object destructuring
Using the spread syntax, (`...`), you can destructure and assign the object with specific properties omitted to a new object. This trick comes in handy especially if you want to remove a subset of properties instead of just one and... | unknown | unknown | [Set the property to undefined > Use object destructuring]
## Use object destructuring
Using the spread syntax, (`...`), you can destructure and assign the object with specific properties omitted to a new object. This trick comes in handy especially if you want to remove a subset of properties instead of just one and... | [Set the property to undefined > Use object destructuring]
## Use object destructuring
Using the spread syntax, (`...`), you can destructure and assign the object with specific properties omitted to a new object. This trick comes in handy especially if you want to remove a subset of properties instead of just one and... | code_snippets | ||
940b948c-bdb9-4e7b-9fd9-c15b2a92444b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-object-property.md | unknown | 37d5b5ed-bd82-4f21-8a2c-c4ead4cfcb01 | 0 | SemanticChunker@1.0.0 | c4e329979b685fad77d480cc7e24fbb1116a438b3117aafb74165967ed87a8dd | ---
title: How do I remove a property from a JavaScript object?
shortTitle: Remove property from object
language: javascript
tags: [object]
cover: brown-bird
excerpt: Ever wanted to delete a property from a JavaScript object? Here are a few way you can accomplish that.
listed: true
dateModified: 2021-06-12
---
When wo... | unknown | unknown | ---
title: How do I remove a property from a JavaScript object?
shortTitle: Remove property from object
language: javascript
tags: [object]
cover: brown-bird
excerpt: Ever wanted to delete a property from a JavaScript object? Here are a few way you can accomplish that.
listed: true
dateModified: 2021-06-12
---
When wo... | ---
title: How do I remove a property from a JavaScript object?
shortTitle: Remove property from object
language: javascript
tags: [object]
cover: brown-bird
excerpt: Ever wanted to delete a property from a JavaScript object? Here are a few way you can accomplish that.
listed: true
dateModified: 2021-06-12
---
When wo... | code_snippets | ||
446d9b24-9b67-4d69-987e-2bf655d40d56 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-trailing-zeros.md | unknown | a6c0b0d3-c3c1-4ccf-9136-d93ce8841fc0 | 2 | SemanticChunker@1.0.0 | 3a5ede0078eae66f8b07bc0f0dedcf324297af7087064eb321c001f83a1df6a6 | [Regular expression > Multiply by 1]
## Multiply by 1
A better way to remove trailing zeros is to multiply by `1`. This method will remove trailing zeros from the decimal part of the number, **accounting for non-zero digits** after the decimal point. The only downside is that **the result is a numeric value**, so it ... | unknown | unknown | [Regular expression > Multiply by 1]
## Multiply by 1
A better way to remove trailing zeros is to multiply by `1`. This method will remove trailing zeros from the decimal part of the number, **accounting for non-zero digits** after the decimal point. The only downside is that **the result is a numeric value**, so it ... | [Regular expression > Multiply by 1]
## Multiply by 1
A better way to remove trailing zeros is to multiply by `1`. This method will remove trailing zeros from the decimal part of the number, **accounting for non-zero digits** after the decimal point. The only downside is that **the result is a numeric value**, so it ... | code_snippets | ||
88789d04-d86a-455f-b4f1-49c0dd8391db | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-trailing-zeros.md | unknown | a6c0b0d3-c3c1-4ccf-9136-d93ce8841fc0 | 1 | SemanticChunker@1.0.0 | 1a0cbedcc8ad6c8a5d114da27ebae604f6862cafc04b7b5cdd9291ea3ef7ae20 | [Regular expression]
## Regular expression
Provided that the number is converted to a **fixed-point string**, you can use a regular expression to remove trailing zeros. All you have to do is match the decimal point (`\.`) and replace any zeros after it (`0+`) until the end of the string (`$`).
```js
const toFixedWit... | unknown | unknown | [Regular expression]
## Regular expression
Provided that the number is converted to a **fixed-point string**, you can use a regular expression to remove trailing zeros. All you have to do is match the decimal point (`\.`) and replace any zeros after it (`0+`) until the end of the string (`$`).
```js
const toFixedWit... | [Regular expression]
## Regular expression
Provided that the number is converted to a **fixed-point string**, you can use a regular expression to remove trailing zeros. All you have to do is match the decimal point (`\.`) and replace any zeros after it (`0+`) until the end of the string (`$`).
```js
const toFixedWit... | code_snippets | ||
94207806-a26b-4e34-920c-9fdab98332f3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-trailing-zeros.md | unknown | a6c0b0d3-c3c1-4ccf-9136-d93ce8841fc0 | 3 | SemanticChunker@1.0.0 | de0b29ae82f7afbcd50ff52c55fb639f09221c71a37b27326b9ac7396c9ea747 | [Regular expression > Number.parseFloat]
## Number.parseFloat
Similar to the previous approach, you can use `Number.parseFloat()` to remove trailing zeros from a number. This method also accounts for non-zero digits after the decimal point. We recommend this approach as it's the **most readable**.
```js
const toFixe... | unknown | unknown | [Regular expression > Number.parseFloat]
## Number.parseFloat
Similar to the previous approach, you can use `Number.parseFloat()` to remove trailing zeros from a number. This method also accounts for non-zero digits after the decimal point. We recommend this approach as it's the **most readable**.
```js
const toFixe... | [Regular expression > Number.parseFloat]
## Number.parseFloat
Similar to the previous approach, you can use `Number.parseFloat()` to remove trailing zeros from a number. This method also accounts for non-zero digits after the decimal point. We recommend this approach as it's the **most readable**.
```js
const toFixe... | code_snippets | ||
a215a0d9-0402-49ed-8f1a-d4f904c02b15 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-trailing-zeros.md | unknown | a6c0b0d3-c3c1-4ccf-9136-d93ce8841fc0 | 0 | SemanticChunker@1.0.0 | ec30202ad9b0f33af971648fc30cff562a4ecf781b67a6b77f48a9c3b46cb7e5 | ---
title: How can I remove trailing zeros from a number in JavaScript?
shortTitle: Remove trailing zeros from number
language: javascript
tags: [number]
cover: island-corridor
excerpt: When formatting decimal values in JavaScript, trailing zeros can be undesired. Here's how to deal with them.
listed: true
dateModified... | unknown | unknown | ---
title: How can I remove trailing zeros from a number in JavaScript?
shortTitle: Remove trailing zeros from number
language: javascript
tags: [number]
cover: island-corridor
excerpt: When formatting decimal values in JavaScript, trailing zeros can be undesired. Here's how to deal with them.
listed: true
dateModified... | ---
title: How can I remove trailing zeros from a number in JavaScript?
shortTitle: Remove trailing zeros from number
language: javascript
tags: [number]
cover: island-corridor
excerpt: When formatting decimal values in JavaScript, trailing zeros can be undesired. Here's how to deal with them.
listed: true
dateModified... | code_snippets | ||
8b152d23-60a3-413f-91b7-2dd4a05652b4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-non-ascii.md | unknown | 416a1a46-bea5-4dfa-97f5-aab27619a6db | 0 | SemanticChunker@1.0.0 | 002900bc596ce203582769d288271ae0e8497f7f210af679e730e75abfbe9ae2 | ---
title: Remove non ASCII characters from a JavaScript string
shortTitle: Remove non ASCII characters
language: javascript
tags: [string,regexp]
cover: blue-red-mountain
excerpt: Remove non-printable ASCII characters from a string in JavaScript.
listed: true
dateModified: 2024-05-18
---
If you're converting text fro... | unknown | unknown | ---
title: Remove non ASCII characters from a JavaScript string
shortTitle: Remove non ASCII characters
language: javascript
tags: [string,regexp]
cover: blue-red-mountain
excerpt: Remove non-printable ASCII characters from a string in JavaScript.
listed: true
dateModified: 2024-05-18
---
If you're converting text fro... | ---
title: Remove non ASCII characters from a JavaScript string
shortTitle: Remove non ASCII characters
language: javascript
tags: [string,regexp]
cover: blue-red-mountain
excerpt: Remove non-printable ASCII characters from a string in JavaScript.
listed: true
dateModified: 2024-05-18
---
If you're converting text fro... | code_snippets | ||
ee207027-3ee6-4b5e-ac68-03295917c6fd | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-elements-from-array.md | unknown | 085bdcf3-0d4e-4050-bab4-0efa334d5916 | 0 | SemanticChunker@1.0.0 | 5fd5e9f0d48c2318bd58c17487f612775b65b191e3a182dc409c93881e7053c2 | ---
title: Remove elements from a JavaScript array without mutating it
shortTitle: Remove elements from array
language: javascript
tags: [array]
cover: chill-surfing
excerpt: Did you know that implementing a non-mutating version of `Array.prototype.splice()` is only a few lines of code?
listed: true
dateModified: 2023-... | unknown | unknown | ---
title: Remove elements from a JavaScript array without mutating it
shortTitle: Remove elements from array
language: javascript
tags: [array]
cover: chill-surfing
excerpt: Did you know that implementing a non-mutating version of `Array.prototype.splice()` is only a few lines of code?
listed: true
dateModified: 2023-... | ---
title: Remove elements from a JavaScript array without mutating it
shortTitle: Remove elements from array
language: javascript
tags: [array]
cover: chill-surfing
excerpt: Did you know that implementing a non-mutating version of `Array.prototype.splice()` is only a few lines of code?
listed: true
dateModified: 2023-... | code_snippets | ||
7815fc93-728d-4379-9c69-a641a5732470 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-element-from-array.md | unknown | 49eb9ef7-5459-4150-8079-9d5c70c1702f | 3 | SemanticChunker@1.0.0 | eec687aadd29ca5214800405cec8f92bdb0ce2c621e343b3fb5de166f7b18762 | [Array.prototype.splice() > Alternative options]
## Alternative options
The previous two options should cover the vast majority of use cases. Yet, there are some other options available for removing elements from an array, which might be preferable in certain cases. For example, if you like the interface of `Array.pr... | unknown | unknown | [Array.prototype.splice() > Alternative options]
## Alternative options
The previous two options should cover the vast majority of use cases. Yet, there are some other options available for removing elements from an array, which might be preferable in certain cases. For example, if you like the interface of `Array.pr... | [Array.prototype.splice() > Alternative options]
## Alternative options
The previous two options should cover the vast majority of use cases. Yet, there are some other options available for removing elements from an array, which might be preferable in certain cases. For example, if you like the interface of `Array.pr... | code_snippets | ||
7e581717-6b13-47be-b733-920464927b8c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-element-from-array.md | unknown | 49eb9ef7-5459-4150-8079-9d5c70c1702f | 2 | SemanticChunker@1.0.0 | bf51428d055777b60f64c420bcd31c238ff295467954869e2a91c1a2f6430844 | [Array.prototype.splice() > Array.prototype.filter()]
## Array.prototype.filter()
Another option for removing elements from an array is `Array.prototype.filter()`. More versatile than `Array.prototype.splice()`, it **doesn't mutate the original array**, but instead returns a new one. However, there's a performance co... | unknown | unknown | [Array.prototype.splice() > Array.prototype.filter()]
## Array.prototype.filter()
Another option for removing elements from an array is `Array.prototype.filter()`. More versatile than `Array.prototype.splice()`, it **doesn't mutate the original array**, but instead returns a new one. However, there's a performance co... | [Array.prototype.splice() > Array.prototype.filter()]
## Array.prototype.filter()
Another option for removing elements from an array is `Array.prototype.filter()`. More versatile than `Array.prototype.splice()`, it **doesn't mutate the original array**, but instead returns a new one. However, there's a performance co... | code_snippets | ||
af0ddf42-6506-4989-b8ba-5b0b8d24ccda | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-element-from-array.md | unknown | 49eb9ef7-5459-4150-8079-9d5c70c1702f | 1 | SemanticChunker@1.0.0 | b2b679ee45d1beba060efe429f8b5db33fbed5d4191f0e4df433fa523f1ef0ab | [Array.prototype.splice()]
## Array.prototype.splice()
This is probably the most common approach for removing elements from an array. While `Array.prototype.splice()` is a very versatile tool in your kit, you need to remember that it **mutates the original array**. On top of that, it returns the deleted elements inst... | unknown | unknown | [Array.prototype.splice()]
## Array.prototype.splice()
This is probably the most common approach for removing elements from an array. While `Array.prototype.splice()` is a very versatile tool in your kit, you need to remember that it **mutates the original array**. On top of that, it returns the deleted elements inst... | [Array.prototype.splice()]
## Array.prototype.splice()
This is probably the most common approach for removing elements from an array. While `Array.prototype.splice()` is a very versatile tool in your kit, you need to remember that it **mutates the original array**. On top of that, it returns the deleted elements inst... | code_snippets | ||
c8ed3026-4dd8-4c48-9f91-5864b2348262 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-element-from-array.md | unknown | 49eb9ef7-5459-4150-8079-9d5c70c1702f | 0 | SemanticChunker@1.0.0 | eb3c745eaa44d0f367df225e96bd1d9dd0cbb07d742be66defc0d41ae31647ac | ---
title: Remove an element from a JavaScript array
shortTitle: Remove element from array
language: javascript
tags: [array]
cover: maple-leaf-palette
excerpt: Did you know there are multiple ways to remove an element from an array? Let's take a look.
listed: true
dateModified: 2022-06-26
---
Removing a specific valu... | unknown | unknown | ---
title: Remove an element from a JavaScript array
shortTitle: Remove element from array
language: javascript
tags: [array]
cover: maple-leaf-palette
excerpt: Did you know there are multiple ways to remove an element from an array? Let's take a look.
listed: true
dateModified: 2022-06-26
---
Removing a specific valu... | ---
title: Remove an element from a JavaScript array
shortTitle: Remove element from array
language: javascript
tags: [array]
cover: maple-leaf-palette
excerpt: Did you know there are multiple ways to remove an element from an array? Let's take a look.
listed: true
dateModified: 2022-06-26
---
Removing a specific valu... | code_snippets | ||
a2f67016-b59d-4815-b140-58ae25ca7af9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/reorder-function-arguments.md | unknown | 04194499-c900-4dc8-847c-948603a4b929 | 2 | SemanticChunker@1.0.0 | 97793260f28741c2f6b672d8cdcef1ac462824873c26443ed348aa1251f7c563 | [Flip function arguments > Rearrange function arguments]
## Rearrange function arguments
If you need yet more control over the order of a function's arguments, you can arrange them based on a **specific order**. This is particularly useful when you have a function with a **large number of arguments** and you want to ... | unknown | unknown | [Flip function arguments > Rearrange function arguments]
## Rearrange function arguments
If you need yet more control over the order of a function's arguments, you can arrange them based on a **specific order**. This is particularly useful when you have a function with a **large number of arguments** and you want to ... | [Flip function arguments > Rearrange function arguments]
## Rearrange function arguments
If you need yet more control over the order of a function's arguments, you can arrange them based on a **specific order**. This is particularly useful when you have a function with a **large number of arguments** and you want to ... | code_snippets | ||
ce8b6a80-e104-4ecf-85ab-c92cc42f97c6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/reorder-function-arguments.md | unknown | 04194499-c900-4dc8-847c-948603a4b929 | 0 | SemanticChunker@1.0.0 | 891e4080e3e3622f27d82500a729a23b680b665c872252f7ec2a6327b6d56b24 | ---
title: Change the order of arguments in a JavaScript function
shortTitle: Reorder function arguments
language: javascript
tags: [function]
cover: interior-11
excerpt: Learn how to reorder the arguments of a JavaScript function to fit your needs.
listed: true
dateModified: 2024-08-05
journeyId: js/functional-program... | unknown | unknown | ---
title: Change the order of arguments in a JavaScript function
shortTitle: Reorder function arguments
language: javascript
tags: [function]
cover: interior-11
excerpt: Learn how to reorder the arguments of a JavaScript function to fit your needs.
listed: true
dateModified: 2024-08-05
journeyId: js/functional-program... | ---
title: Change the order of arguments in a JavaScript function
shortTitle: Reorder function arguments
language: javascript
tags: [function]
cover: interior-11
excerpt: Learn how to reorder the arguments of a JavaScript function to fit your needs.
listed: true
dateModified: 2024-08-05
journeyId: js/functional-program... | code_snippets | ||
eb5e374a-75ad-4081-b1c1-58e8d4c6a959 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/reorder-function-arguments.md | unknown | 04194499-c900-4dc8-847c-948603a4b929 | 1 | SemanticChunker@1.0.0 | 5db9e74d86ef46c4ee50393d6b1c191b1cc0db842bae48c15712184dde9fc915 | [Flip function arguments]
## Flip function arguments
A very common need is to **make the first argument the last**. This is particularly useful when [currying a function](/js/s/currying) or when you need to [partially apply a function](/js/s/partially-apply-function).
You can easily achieve this by using a [**higher... | unknown | unknown | [Flip function arguments]
## Flip function arguments
A very common need is to **make the first argument the last**. This is particularly useful when [currying a function](/js/s/currying) or when you need to [partially apply a function](/js/s/partially-apply-function).
You can easily achieve this by using a [**higher... | [Flip function arguments]
## Flip function arguments
A very common need is to **make the first argument the last**. This is particularly useful when [currying a function](/js/s/currying) or when you need to [partially apply a function](/js/s/partially-apply-function).
You can easily achieve this by using a [**higher... | code_snippets | ||
e521c179-6e74-4ef5-80d5-ec936bdd64f3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/remove-dom-element.md | unknown | 2aeb349b-d89c-4fd5-b6a2-ff206b524e2b | 0 | SemanticChunker@1.0.0 | dbfc4b21b3bf16abc7c6aec66ff2a649989c6c0dfb911e307ef248976ff9d6f9 | ---
title: Remove an element from the DOM using JavaScript
shortTitle: Remove DOM element
language: javascript
tags: [browser]
cover: by-the-lighthouse
excerpt: Learn how to quickly remove an element from the DOM using JavaScript.
listed: true
dateModified: 2024-07-04
---
DOM manipulation is one of the primary reasons... | unknown | unknown | ---
title: Remove an element from the DOM using JavaScript
shortTitle: Remove DOM element
language: javascript
tags: [browser]
cover: by-the-lighthouse
excerpt: Learn how to quickly remove an element from the DOM using JavaScript.
listed: true
dateModified: 2024-07-04
---
DOM manipulation is one of the primary reasons... | ---
title: Remove an element from the DOM using JavaScript
shortTitle: Remove DOM element
language: javascript
tags: [browser]
cover: by-the-lighthouse
excerpt: Learn how to quickly remove an element from the DOM using JavaScript.
listed: true
dateModified: 2024-07-04
---
DOM manipulation is one of the primary reasons... | code_snippets | ||
a4bef22c-fa44-4f76-bf95-2c7b464ba9f2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/select-focused-dom-element.md | unknown | 3219b44d-d614-4d10-8758-b6fba72e9663 | 0 | SemanticChunker@1.0.0 | bb296c72caa427085b88c5c85528b03abb0265097b5a639dc2c6a4445c50b034 | ---
title: Select the focused DOM element with JavaScript
shortTitle: Focused DOM element
language: javascript
tags: [browser]
cover: horse-sunset
excerpt: Here's a quick and easy way to select the currently focused DOM element in JavaScript.
listed: true
dateModified: 2022-10-23
---
Finding the currently focused DOM ... | unknown | unknown | ---
title: Select the focused DOM element with JavaScript
shortTitle: Focused DOM element
language: javascript
tags: [browser]
cover: horse-sunset
excerpt: Here's a quick and easy way to select the currently focused DOM element in JavaScript.
listed: true
dateModified: 2022-10-23
---
Finding the currently focused DOM ... | ---
title: Select the focused DOM element with JavaScript
shortTitle: Focused DOM element
language: javascript
tags: [browser]
cover: horse-sunset
excerpt: Here's a quick and easy way to select the currently focused DOM element in JavaScript.
listed: true
dateModified: 2022-10-23
---
Finding the currently focused DOM ... | code_snippets | ||
31a349b1-f5db-42a1-9b0c-d1c47cb75bb3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/scroll-to-top.md | unknown | 1b27ab29-2d64-4b6e-8e0e-e755c9aff5f3 | 0 | SemanticChunker@1.0.0 | 4e69f549ff250c3e249d77840a0a2b4ff6041cf1b7bc01aa1c37a4e1012953db | ---
title: Smooth scroll to the top of the page using JavaScript
shortTitle: Scroll to page top
language: javascript
tags: [browser]
cover: tranquil-lake
excerpt: Smooth-scrolls to the top of the page.
listed: true
dateModified: 2024-08-07
---
When you want to scroll to the top of the page, you can do so instantly or ... | unknown | unknown | ---
title: Smooth scroll to the top of the page using JavaScript
shortTitle: Scroll to page top
language: javascript
tags: [browser]
cover: tranquil-lake
excerpt: Smooth-scrolls to the top of the page.
listed: true
dateModified: 2024-08-07
---
When you want to scroll to the top of the page, you can do so instantly or ... | ---
title: Smooth scroll to the top of the page using JavaScript
shortTitle: Scroll to page top
language: javascript
tags: [browser]
cover: tranquil-lake
excerpt: Smooth-scrolls to the top of the page.
listed: true
dateModified: 2024-08-07
---
When you want to scroll to the top of the page, you can do so instantly or ... | code_snippets | ||
5b0308d8-4019-44e4-a667-2633249ae5bc | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/rgb-to-array-or-object.md | unknown | 822c4e9a-725c-470b-88c1-40b3eb21972e | 1 | SemanticChunker@1.0.0 | 85c88de6c6b4b1604c158389f11d6f1773510f949ecd4b45cae81c3a90df7a8f | [Convert an `rgb()` color string to an array]
## Convert an `rgb()` color string to an array
In order to convert an `rgb()` color string to an **array of values**, you can use `String.prototype.match()` to get an array of 3 strings with the numeric values, and then use `Array.prototype.map()` in combination with `Num... | unknown | unknown | [Convert an `rgb()` color string to an array]
## Convert an `rgb()` color string to an array
In order to convert an `rgb()` color string to an **array of values**, you can use `String.prototype.match()` to get an array of 3 strings with the numeric values, and then use `Array.prototype.map()` in combination with `Num... | [Convert an `rgb()` color string to an array]
## Convert an `rgb()` color string to an array
In order to convert an `rgb()` color string to an **array of values**, you can use `String.prototype.match()` to get an array of 3 strings with the numeric values, and then use `Array.prototype.map()` in combination with `Num... | code_snippets | ||
5cba5f06-cf73-44d0-8a4e-f08f66652d05 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/rgb-to-array-or-object.md | unknown | 822c4e9a-725c-470b-88c1-40b3eb21972e | 2 | SemanticChunker@1.0.0 | 58c0867597d2ad811f0fb8856357acf4145192765dcacc6be38c03aaf55a8849 | [Convert an `rgb()` color string to an array > Convert an `rgb()` color string to an object]
## Convert an `rgb()` color string to an object
Subsequently, you can use **array destructuring** on top of the previous approach to store the values into named variables and create an appropriate object from them. This allow... | unknown | unknown | [Convert an `rgb()` color string to an array > Convert an `rgb()` color string to an object]
## Convert an `rgb()` color string to an object
Subsequently, you can use **array destructuring** on top of the previous approach to store the values into named variables and create an appropriate object from them. This allow... | [Convert an `rgb()` color string to an array > Convert an `rgb()` color string to an object]
## Convert an `rgb()` color string to an object
Subsequently, you can use **array destructuring** on top of the previous approach to store the values into named variables and create an appropriate object from them. This allow... | code_snippets | ||
68f5f447-0b06-46da-a8f7-b6651566bbcd | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/rgb-to-array-or-object.md | unknown | 822c4e9a-725c-470b-88c1-40b3eb21972e | 0 | SemanticChunker@1.0.0 | fe31a16e7c3a55c775e8e9b0b9b5f574201fd506934ac9e45a115d6e8ca58fd2 | ---
title: Convert an RGB color string to a JavaScript array or object
shortTitle: RGB to array or object
language: javascript
tags: [string,regexp]
cover: greek-coffee
excerpt: Easily convert an `rgb()` color string to an array of values or an object with the values of each color.
listed: true
dateModified: 2024-03-06... | unknown | unknown | ---
title: Convert an RGB color string to a JavaScript array or object
shortTitle: RGB to array or object
language: javascript
tags: [string,regexp]
cover: greek-coffee
excerpt: Easily convert an `rgb()` color string to an array of values or an object with the values of each color.
listed: true
dateModified: 2024-03-06... | ---
title: Convert an RGB color string to a JavaScript array or object
shortTitle: RGB to array or object
language: javascript
tags: [string,regexp]
cover: greek-coffee
excerpt: Easily convert an `rgb()` color string to an array of values or an object with the values of each color.
listed: true
dateModified: 2024-03-06... | code_snippets | ||
0abfac9a-aff6-4edd-b167-18f2be7ac5af | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/return-constructor.md | unknown | 957d48a4-5cac-42bd-a176-e55e8e0815bc | 0 | SemanticChunker@1.0.0 | cbecd051f1e463a4096be3ec08daf934778f517384ca5102e6d2e7867e678a35 | ---
title: What does a JavaScript constructor return?
shortTitle: Constructor return value
language: javascript
tags: [function,class,object]
cover: architectural
excerpt: The constructor is a crucial part of any JavaScript class, which is why you might want to take a closer look at what they return.
listed: true
dateM... | unknown | unknown | ---
title: What does a JavaScript constructor return?
shortTitle: Constructor return value
language: javascript
tags: [function,class,object]
cover: architectural
excerpt: The constructor is a crucial part of any JavaScript class, which is why you might want to take a closer look at what they return.
listed: true
dateM... | ---
title: What does a JavaScript constructor return?
shortTitle: Constructor return value
language: javascript
tags: [function,class,object]
cover: architectural
excerpt: The constructor is a crucial part of any JavaScript class, which is why you might want to take a closer look at what they return.
listed: true
dateM... | code_snippets | ||
200e07d5-6521-462a-867e-36764aa6c54a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/return-constructor.md | unknown | 957d48a4-5cac-42bd-a176-e55e8e0815bc | 1 | SemanticChunker@1.0.0 | 197846bfe8810d0f55ba245850d6f28cf4bfc2996893eab35cd1e8f572dac380 | ```js
class VerboseClass {
constructor() {
this.val = 0;
return this;
}
}
new VerboseClass(); // { val: 0 }
class PrimClass {
constructor() {
this.val = 0;
return 20;
}
}
new PrimitiveClass(); // { val: 0 }
```
The two examples above are not optimal, each for a different reason. The first one is too verbose, ... | unknown | unknown | ```js
class VerboseClass {
constructor() {
this.val = 0;
return this;
}
}
new VerboseClass(); // { val: 0 }
class PrimClass {
constructor() {
this.val = 0;
return 20;
}
}
new PrimitiveClass(); // { val: 0 }
```
The two examples above are not optimal, each for a different reason. The first one is too verbose, ... | ```js
class VerboseClass {
constructor() {
this.val = 0;
return this;
}
}
new VerboseClass(); // { val: 0 }
class PrimClass {
constructor() {
this.val = 0;
return 20;
}
}
new PrimitiveClass(); // { val: 0 }
```
The two examples above are not optimal, each for a different reason. The first one is too verbose, ... | code_snippets | ||
139a8cec-7b79-4380-9940-c0e4fcd54b98 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/run-promises-in-series.md | unknown | 179dfd8f-4001-4bb9-89dd-94e6e471443b | 0 | SemanticChunker@1.0.0 | 660eb185cad94722a65a2ed369a6fa81b6ad61804afe56cdc9b919626e70c036 | ---
title: Run JavaScript promises in series
shortTitle: Run promises in series
language: javascript
tags: [promises,function]
cover: sail-away
excerpt: Learn how to resolve promises one after another (sequentially) in JavaScript.
listed: true
dateModified: 2023-10-15
---
JavaScript **promises are asynchronous**, mean... | unknown | unknown | ---
title: Run JavaScript promises in series
shortTitle: Run promises in series
language: javascript
tags: [promises,function]
cover: sail-away
excerpt: Learn how to resolve promises one after another (sequentially) in JavaScript.
listed: true
dateModified: 2023-10-15
---
JavaScript **promises are asynchronous**, mean... | ---
title: Run JavaScript promises in series
shortTitle: Run promises in series
language: javascript
tags: [promises,function]
cover: sail-away
excerpt: Learn how to resolve promises one after another (sequentially) in JavaScript.
listed: true
dateModified: 2023-10-15
---
JavaScript **promises are asynchronous**, mean... | code_snippets | ||
9a65a8d7-fc4d-4a4f-a0da-d3f2e53debb4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/resolve-promise-after-amount-of-time.md | unknown | 630af596-e1a6-4a4a-bac5-4a6ff97b50de | 0 | SemanticChunker@1.0.0 | 0c400b5e4fd40b1b375a3f718ef384bc5c4a764a1939d7bac9b9d0d85eb1330d | ---
title: Create a JavaScript promise that resolves after a given amount of time
shortTitle: Resolve promise after given amount of time
language: javascript
tags: [promises,function]
cover: filter-coffee-pot
excerpt: Learn how to create a promise that resolves after a given amount of time in JavaScript.
listed: true
d... | unknown | unknown | ---
title: Create a JavaScript promise that resolves after a given amount of time
shortTitle: Resolve promise after given amount of time
language: javascript
tags: [promises,function]
cover: filter-coffee-pot
excerpt: Learn how to create a promise that resolves after a given amount of time in JavaScript.
listed: true
d... | ---
title: Create a JavaScript promise that resolves after a given amount of time
shortTitle: Resolve promise after given amount of time
language: javascript
tags: [promises,function]
cover: filter-coffee-pot
excerpt: Learn how to create a promise that resolves after a given amount of time in JavaScript.
listed: true
d... | code_snippets | ||
70b08cdb-23ed-49da-a148-57547883ff15 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/replace-or-append-array-value.md | unknown | 11393e7b-d64c-4d90-923a-58c578cd9fc9 | 0 | SemanticChunker@1.0.0 | eec0cfecb665bba94d72e0058c94643c4f463aa4912818aa8665f32853db0296 | ---
title: Replace or append a value in a JavaScript array
shortTitle: Replace or append array value
language: javascript
tags: [array]
cover: boutique-home-office-2
excerpt: Quickly and easily replace or append a value in a JavaScript array.
listed: true
dateModified: 2024-03-23
---
When working with arrays in JavaSc... | unknown | unknown | ---
title: Replace or append a value in a JavaScript array
shortTitle: Replace or append array value
language: javascript
tags: [array]
cover: boutique-home-office-2
excerpt: Quickly and easily replace or append a value in a JavaScript array.
listed: true
dateModified: 2024-03-23
---
When working with arrays in JavaSc... | ---
title: Replace or append a value in a JavaScript array
shortTitle: Replace or append array value
language: javascript
tags: [array]
cover: boutique-home-office-2
excerpt: Quickly and easily replace or append a value in a JavaScript array.
listed: true
dateModified: 2024-03-23
---
When working with arrays in JavaSc... | code_snippets | ||
1806640e-b90f-451d-998d-6dfd14c7a77d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/replace-last-occurrence.md | unknown | 583e3075-3b73-470d-840e-e101ece6c3ec | 1 | SemanticChunker@1.0.0 | 56891e4a54100ce01316767258a5425f1355cd76f66579a3eaba2384869679be | ```js
const replaceLast = (str, pattern, replacement) => {
const match =
typeof pattern === 'string'
? pattern
: (str.match(new RegExp(pattern.source, 'g')) || []).slice(-1)[0];
if (!match) return str;
const last = str.lastIndexOf(match);
return last !== -1
? `${str.slice(0, last)}${replacement}${str.slice(last... | unknown | unknown | ```js
const replaceLast = (str, pattern, replacement) => {
const match =
typeof pattern === 'string'
? pattern
: (str.match(new RegExp(pattern.source, 'g')) || []).slice(-1)[0];
if (!match) return str;
const last = str.lastIndexOf(match);
return last !== -1
? `${str.slice(0, last)}${replacement}${str.slice(last... | ```js
const replaceLast = (str, pattern, replacement) => {
const match =
typeof pattern === 'string'
? pattern
: (str.match(new RegExp(pattern.source, 'g')) || []).slice(-1)[0];
if (!match) return str;
const last = str.lastIndexOf(match);
return last !== -1
? `${str.slice(0, last)}${replacement}${str.slice(last... | code_snippets | ||
a3f41b29-ac5d-4b05-bd01-451de9e99414 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/replace-last-occurrence.md | unknown | 583e3075-3b73-470d-840e-e101ece6c3ec | 0 | SemanticChunker@1.0.0 | 0cf385251e620762a9844ecaa33657a5a8d4f3631b023df7c0429dfbd1f9ec8e | ---
title: Replace the last occurrence of a pattern in a JavaScript string
shortTitle: Replace last occurrence
language: javascript
tags: [string,regexp]
cover: waves
excerpt: Learn how to use regular expressions to replace the last occurrence of a pattern in a JavaScript string.
listed: true
dateModified: 2024-02-08
-... | unknown | unknown | ---
title: Replace the last occurrence of a pattern in a JavaScript string
shortTitle: Replace last occurrence
language: javascript
tags: [string,regexp]
cover: waves
excerpt: Learn how to use regular expressions to replace the last occurrence of a pattern in a JavaScript string.
listed: true
dateModified: 2024-02-08
-... | ---
title: Replace the last occurrence of a pattern in a JavaScript string
shortTitle: Replace last occurrence
language: javascript
tags: [string,regexp]
cover: waves
excerpt: Learn how to use regular expressions to replace the last occurrence of a pattern in a JavaScript string.
listed: true
dateModified: 2024-02-08
-... | code_snippets | ||
0e121c0a-2810-48e8-8663-1da19a26c39c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/replace-all-occurences-of-string.md | unknown | 54cd758d-5a4d-4b2b-b46b-12daea225544 | 0 | SemanticChunker@1.0.0 | a7e7c1dd62a3b090f47d773dbef9a2d7fb004424817d6b131cd59e2022796e2e | ---
title: Replace all occurrences of a string in JavaScript
shortTitle: Replace all occurrences of a string
language: javascript
tags: [string,regexp]
cover: blue-computer
excerpt: If you need to replace all occurrences of a string in JavaScript, you have a couple of options.
listed: true
dateModified: 2022-07-03
--- | unknown | unknown | ---
title: Replace all occurrences of a string in JavaScript
shortTitle: Replace all occurrences of a string
language: javascript
tags: [string,regexp]
cover: blue-computer
excerpt: If you need to replace all occurrences of a string in JavaScript, you have a couple of options.
listed: true
dateModified: 2022-07-03
--- | ---
title: Replace all occurrences of a string in JavaScript
shortTitle: Replace all occurrences of a string
language: javascript
tags: [string,regexp]
cover: blue-computer
excerpt: If you need to replace all occurrences of a string in JavaScript, you have a couple of options.
listed: true
dateModified: 2022-07-03
--- | code_snippets | ||
294fda24-cf4b-411c-9642-b93ce3a3d2d8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/replace-all-occurences-of-string.md | unknown | 54cd758d-5a4d-4b2b-b46b-12daea225544 | 2 | SemanticChunker@1.0.0 | 65b253f37edfd5123bd26938b1786730f07c81ac0af8c1950913e327271dc319 | [String.prototype.replaceAll() > String.prototype.replace()]
## String.prototype.replace()
Before the introduction of `String.prototype.replaceAll()`, `String.prototype.replace()` was the method of choice for this sort of task. It's supported by all JavaScript engines, old and new and is very similar to `String.proto... | unknown | unknown | [String.prototype.replaceAll() > String.prototype.replace()]
## String.prototype.replace()
Before the introduction of `String.prototype.replaceAll()`, `String.prototype.replace()` was the method of choice for this sort of task. It's supported by all JavaScript engines, old and new and is very similar to `String.proto... | [String.prototype.replaceAll() > String.prototype.replace()]
## String.prototype.replace()
Before the introduction of `String.prototype.replaceAll()`, `String.prototype.replace()` was the method of choice for this sort of task. It's supported by all JavaScript engines, old and new and is very similar to `String.proto... | code_snippets | ||
d968345d-bf31-4bf2-bab2-3d42f3efb935 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/replace-all-occurences-of-string.md | unknown | 54cd758d-5a4d-4b2b-b46b-12daea225544 | 1 | SemanticChunker@1.0.0 | 4dce7ecf7c9ff88eb63f12d6215029e2f3e46466907be5c5fd807556a6591c2b | [String.prototype.replaceAll()]
## String.prototype.replaceAll()
Modern JavaScript engines have a built-in method called `String.prototype.replaceAll()`. This method can be used to replace all occurrences of a string in another string with relative ease.
```js
const str = 'Hello World';
str.replaceAll('o', 'x'); //... | unknown | unknown | [String.prototype.replaceAll()]
## String.prototype.replaceAll()
Modern JavaScript engines have a built-in method called `String.prototype.replaceAll()`. This method can be used to replace all occurrences of a string in another string with relative ease.
```js
const str = 'Hello World';
str.replaceAll('o', 'x'); //... | [String.prototype.replaceAll()]
## String.prototype.replaceAll()
Modern JavaScript engines have a built-in method called `String.prototype.replaceAll()`. This method can be used to replace all occurrences of a string in another string with relative ease.
```js
const str = 'Hello World';
str.replaceAll('o', 'x'); //... | code_snippets | ||
21af6768-2a70-4b7d-b276-48956cc16e58 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/rgb-hex-hsl-hsb-color-format-conversion.md | unknown | 4f7b388c-3f58-4cec-8ffb-e35048c1bfd4 | 5 | SemanticChunker@1.0.0 | 4f31e83831690d53a77d6a2caa0850840a90bf31653e0568cf04fc2f7e2a2399 | [Color formats > HSL to RGB]
## HSL to RGB
Similarly, converting from HSL to RGB requires implementing the [HSL to RGB conversion formula](https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB). The **input parameters** are expected to be in the range of H: [0, 360], S: [0, 100], L: [0, 100], while the range of all **... | unknown | unknown | [Color formats > HSL to RGB]
## HSL to RGB
Similarly, converting from HSL to RGB requires implementing the [HSL to RGB conversion formula](https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB). The **input parameters** are expected to be in the range of H: [0, 360], S: [0, 100], L: [0, 100], while the range of all **... | [Color formats > HSL to RGB]
## HSL to RGB
Similarly, converting from HSL to RGB requires implementing the [HSL to RGB conversion formula](https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB). The **input parameters** are expected to be in the range of H: [0, 360], S: [0, 100], L: [0, 100], while the range of all **... | code_snippets | ||
2ebe05e7-5bf8-4aed-a162-44ca746f8d78 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/rgb-hex-hsl-hsb-color-format-conversion.md | unknown | 4f7b388c-3f58-4cec-8ffb-e35048c1bfd4 | 3 | SemanticChunker@1.0.0 | 968e3fa45629d1b9200cc68125080028e7477309b05dba346aedd751fc9433b1 | [Color formats > Hexadecimal to RGB]
## Hexadecimal to RGB
Converting the other way round, from hexadecimal to RGB, is a little more involved. In order to **isolate the color components** from the hexadecimal string, we'll have to use bitwise right-shift and mask bits with `&` (and) operator.
Additionally, we need t... | unknown | unknown | [Color formats > Hexadecimal to RGB]
## Hexadecimal to RGB
Converting the other way round, from hexadecimal to RGB, is a little more involved. In order to **isolate the color components** from the hexadecimal string, we'll have to use bitwise right-shift and mask bits with `&` (and) operator.
Additionally, we need t... | [Color formats > Hexadecimal to RGB]
## Hexadecimal to RGB
Converting the other way round, from hexadecimal to RGB, is a little more involved. In order to **isolate the color components** from the hexadecimal string, we'll have to use bitwise right-shift and mask bits with `&` (and) operator.
Additionally, we need t... | code_snippets | ||
4364a39f-b206-4032-9189-119589bd8e58 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/rgb-hex-hsl-hsb-color-format-conversion.md | unknown | 4f7b388c-3f58-4cec-8ffb-e35048c1bfd4 | 4 | SemanticChunker@1.0.0 | 82aba60a44e3c81171091c73b66e16ff4508e11b01aa360d00ec30a1b5756051 | [Color formats > RGB to HSL]
## RGB to HSL
As the math behind colorspace conversions can be quite complex, delving into details of the conversion formula is beyond the scope of this article. Implementing the [RGB to HSL conversion formula](https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB) is fairly straightforward ... | unknown | unknown | [Color formats > RGB to HSL]
## RGB to HSL
As the math behind colorspace conversions can be quite complex, delving into details of the conversion formula is beyond the scope of this article. Implementing the [RGB to HSL conversion formula](https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB) is fairly straightforward ... | [Color formats > RGB to HSL]
## RGB to HSL
As the math behind colorspace conversions can be quite complex, delving into details of the conversion formula is beyond the scope of this article. Implementing the [RGB to HSL conversion formula](https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB) is fairly straightforward ... | code_snippets | ||
4bc3304f-70ac-4b7b-8eb8-522cfd14f2ff | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/rgb-hex-hsl-hsb-color-format-conversion.md | unknown | 4f7b388c-3f58-4cec-8ffb-e35048c1bfd4 | 7 | SemanticChunker@1.0.0 | a02618b3f17c7e04c993eeaa03c11f2fc592981558e49483655868d365a64bf3 | [Color formats > HSB to RGB]
## HSB to RGB
Converting from HSB to RGB is equally straightforward, and requires implementing the [HSB to RGB conversion formula](https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB). The range of the **input parameters** is H: [0, 360], S: [0, 100], B: [0, 100], while the range of all ... | unknown | unknown | [Color formats > HSB to RGB]
## HSB to RGB
Converting from HSB to RGB is equally straightforward, and requires implementing the [HSB to RGB conversion formula](https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB). The range of the **input parameters** is H: [0, 360], S: [0, 100], B: [0, 100], while the range of all ... | [Color formats > HSB to RGB]
## HSB to RGB
Converting from HSB to RGB is equally straightforward, and requires implementing the [HSB to RGB conversion formula](https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB). The range of the **input parameters** is H: [0, 360], S: [0, 100], B: [0, 100], while the range of all ... | code_snippets | ||
7e0bf201-d282-4ec1-91f3-ef7b9588ec9d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/rgb-hex-hsl-hsb-color-format-conversion.md | unknown | 4f7b388c-3f58-4cec-8ffb-e35048c1bfd4 | 6 | SemanticChunker@1.0.0 | fe8dcd7c6b105b8f7d72a821ec2ee66d41a26c46f4e0b97b328ce756c8a2b8ce | [Color formats > RGB to HSB]
## RGB to HSB
Much like HSL, HSB is another color format that can be derived from RGB. The [RGB to HSB conversion formula](https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB) is equally complex, but can be implemented in a few lines of code.
The range of all **input parameters** is [0, 2... | unknown | unknown | [Color formats > RGB to HSB]
## RGB to HSB
Much like HSL, HSB is another color format that can be derived from RGB. The [RGB to HSB conversion formula](https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB) is equally complex, but can be implemented in a few lines of code.
The range of all **input parameters** is [0, 2... | [Color formats > RGB to HSB]
## RGB to HSB
Much like HSL, HSB is another color format that can be derived from RGB. The [RGB to HSB conversion formula](https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB) is equally complex, but can be implemented in a few lines of code.
The range of all **input parameters** is [0, 2... | code_snippets | ||
a0e61bc4-73ec-4a78-9c5a-b0fcaddb29b4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/rgb-hex-hsl-hsb-color-format-conversion.md | unknown | 4f7b388c-3f58-4cec-8ffb-e35048c1bfd4 | 9 | SemanticChunker@1.0.0 | ec35dd6ad213339170ec68dbdbda00390273e8469f41eba63698ec50d5e8460d | [Color formats > HSB to HSL]
## HSB to HSL
Converting from HSB to HSL is equally straightforward, and requires implementing the [HSB to HSL conversion formula](https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL), which is the inverse of the HSL to HSB formula.
The range of the **input parameters** is H: [0, 360], ... | unknown | unknown | [Color formats > HSB to HSL]
## HSB to HSL
Converting from HSB to HSL is equally straightforward, and requires implementing the [HSB to HSL conversion formula](https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL), which is the inverse of the HSL to HSB formula.
The range of the **input parameters** is H: [0, 360], ... | [Color formats > HSB to HSL]
## HSB to HSL
Converting from HSB to HSL is equally straightforward, and requires implementing the [HSB to HSL conversion formula](https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL), which is the inverse of the HSL to HSB formula.
The range of the **input parameters** is H: [0, 360], ... | code_snippets | ||
d62229eb-9dff-49f2-9d53-bf261545a267 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/rgb-hex-hsl-hsb-color-format-conversion.md | unknown | 4f7b388c-3f58-4cec-8ffb-e35048c1bfd4 | 8 | SemanticChunker@1.0.0 | 938b6fcb7e917177580a34be06df6d8447faed5b10fb307226607d446ae5032b | [Color formats > HSL to HSB]
## HSL to HSB
Converting from HSL to HSB is a matter of **scaling the saturation and lightness** values to match the brightness value. This can be done using [a simple formula](https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV), where the saturation is multiplied by the minimum of the ... | unknown | unknown | [Color formats > HSL to HSB]
## HSL to HSB
Converting from HSL to HSB is a matter of **scaling the saturation and lightness** values to match the brightness value. This can be done using [a simple formula](https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV), where the saturation is multiplied by the minimum of the ... | [Color formats > HSL to HSB]
## HSL to HSB
Converting from HSL to HSB is a matter of **scaling the saturation and lightness** values to match the brightness value. This can be done using [a simple formula](https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV), where the saturation is multiplied by the minimum of the ... | code_snippets | ||
d6baae71-4f16-4ead-a4f3-e51de0e04241 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/rgb-hex-hsl-hsb-color-format-conversion.md | unknown | 4f7b388c-3f58-4cec-8ffb-e35048c1bfd4 | 1 | SemanticChunker@1.0.0 | 3e7a5dddb89dacefe10b03c729a2d5c4048000ed7ca19404252dd7d39d6f8ba2 | [Color formats]
## Color formats
Before diving into conversion formulas, it's worth discussing the different color formats briefly:
- **Hexadecimal**: A **6-digit hexadecimal representation** of a color, with 2 digits for each of the red, green and blue components. For example, `#ff0000` represents the color red.
- ... | unknown | unknown | [Color formats]
## Color formats
Before diving into conversion formulas, it's worth discussing the different color formats briefly:
- **Hexadecimal**: A **6-digit hexadecimal representation** of a color, with 2 digits for each of the red, green and blue components. For example, `#ff0000` represents the color red.
- ... | [Color formats]
## Color formats
Before diving into conversion formulas, it's worth discussing the different color formats briefly:
- **Hexadecimal**: A **6-digit hexadecimal representation** of a color, with 2 digits for each of the red, green and blue components. For example, `#ff0000` represents the color red.
- ... | code_snippets | ||
ed1c1c60-dfac-4283-bd44-4d0e2f2117c2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/rgb-hex-hsl-hsb-color-format-conversion.md | unknown | 4f7b388c-3f58-4cec-8ffb-e35048c1bfd4 | 0 | SemanticChunker@1.0.0 | 756de4fa135d326ceb9e4473d4a89f28506796979c98e1cf4246c9716b987d9a | ---
title: How can I convert between hexadecimal, RGB, HSL and HSB color formats in JavaScript?
shortTitle: Color format conversion
language: javascript
tags: [number]
cover: lemon-tea
excerpt: Learn how to easily convert between the various color formats, using JavaScript and a few simple formulas.
listed: true
dateMo... | unknown | unknown | ---
title: How can I convert between hexadecimal, RGB, HSL and HSB color formats in JavaScript?
shortTitle: Color format conversion
language: javascript
tags: [number]
cover: lemon-tea
excerpt: Learn how to easily convert between the various color formats, using JavaScript and a few simple formulas.
listed: true
dateMo... | ---
title: How can I convert between hexadecimal, RGB, HSL and HSB color formats in JavaScript?
shortTitle: Color format conversion
language: javascript
tags: [number]
cover: lemon-tea
excerpt: Learn how to easily convert between the various color formats, using JavaScript and a few simple formulas.
listed: true
dateMo... | code_snippets |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.