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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
d67f28b8-7fcf-4e35-98f6-bf2a29da8bf6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/indent-string.md | unknown | 64b1e240-ae84-445c-8788-4274cd73748c | 0 | SemanticChunker@1.0.0 | cc2675aca76dd2e9eb2792ef8a5303c8a313a76f4e656f7a9ae1efc390e94f0b | ---
title: Indent a JavaScript string
shortTitle: Indent string
language: javascript
tags: [string]
cover: metropolitan-window
excerpt: Indent each line in a string by a specified number of spaces or a custom indentation character.
listed: true
dateModified: 2024-05-19
---
A problem I've stumbled upon a few times is i... | unknown | unknown | ---
title: Indent a JavaScript string
shortTitle: Indent string
language: javascript
tags: [string]
cover: metropolitan-window
excerpt: Indent each line in a string by a specified number of spaces or a custom indentation character.
listed: true
dateModified: 2024-05-19
---
A problem I've stumbled upon a few times is i... | ---
title: Indent a JavaScript string
shortTitle: Indent string
language: javascript
tags: [string]
cover: metropolitan-window
excerpt: Indent each line in a string by a specified number of spaces or a custom indentation character.
listed: true
dateModified: 2024-05-19
---
A problem I've stumbled upon a few times is i... | code_snippets | ||
697e8530-18bc-430c-b3b7-de2098bb92f1 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/immutability.md | unknown | 071a8925-168c-48eb-b74d-8e05af75c6ad | 0 | SemanticChunker@1.0.0 | 4585f2e5cbe86cff3cf513fca487fdd33a367fb5f67b4e795b3cdfa24ed138ba | ---
title: Immutability in functional programming
shortTitle: Immutability
language: javascript
tags: [webdev]
cover: stars-n-snow
excerpt: Immutability is a fundamental concept you should be familiar with when learning functional programming.
listed: true
dateModified: 2023-12-14
journeyId: js/functional-programming
-... | unknown | unknown | ---
title: Immutability in functional programming
shortTitle: Immutability
language: javascript
tags: [webdev]
cover: stars-n-snow
excerpt: Immutability is a fundamental concept you should be familiar with when learning functional programming.
listed: true
dateModified: 2023-12-14
journeyId: js/functional-programming
-... | ---
title: Immutability in functional programming
shortTitle: Immutability
language: javascript
tags: [webdev]
cover: stars-n-snow
excerpt: Immutability is a fundamental concept you should be familiar with when learning functional programming.
listed: true
dateModified: 2023-12-14
journeyId: js/functional-programming
-... | code_snippets | ||
13cd90e3-ef4e-428e-b373-d7f8ead03bf6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/http-get-post-put-delete.md | unknown | 7d4df65c-86b3-47bc-b5f2-15f2e67f1693 | 2 | SemanticChunker@1.0.0 | 3452e33b0d3d3ede3e41b7a8f2b28e0cae3c3d8fc92e37101cc5c1f97042b4fb | [Using the Fetch API > HTTP GET request]
### HTTP GET request
The simplest use case is to make a `GET` request to a given URL. As the `fetch()` API returns a promise, you can use the `then` method to handle the response. In the following example, the response is converted to JSON using the `json()` method and then lo... | unknown | unknown | [Using the Fetch API > HTTP GET request]
### HTTP GET request
The simplest use case is to make a `GET` request to a given URL. As the `fetch()` API returns a promise, you can use the `then` method to handle the response. In the following example, the response is converted to JSON using the `json()` method and then lo... | [Using the Fetch API > HTTP GET request]
### HTTP GET request
The simplest use case is to make a `GET` request to a given URL. As the `fetch()` API returns a promise, you can use the `then` method to handle the response. In the following example, the response is converted to JSON using the `json()` method and then lo... | code_snippets | ||
233a52f1-46e2-4274-8646-7883b69f78af | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/http-get-post-put-delete.md | unknown | 7d4df65c-86b3-47bc-b5f2-15f2e67f1693 | 3 | SemanticChunker@1.0.0 | a74c9a4affad9d16c6d6fae8789cdf4aa7cf53e96971e522b69bf6c9f2447a0a | [HTTP GET request > HTTP POST request]
### HTTP POST request
To make a `POST` request, you need to pass an object with the request options as the second argument to `fetch()`. The `method` option is set to `'POST'`, and the `body` option is set to the data you want to send.
The type of data in the `body` option can ... | unknown | unknown | [HTTP GET request > HTTP POST request]
### HTTP POST request
To make a `POST` request, you need to pass an object with the request options as the second argument to `fetch()`. The `method` option is set to `'POST'`, and the `body` option is set to the data you want to send.
The type of data in the `body` option can ... | [HTTP GET request > HTTP POST request]
### HTTP POST request
To make a `POST` request, you need to pass an object with the request options as the second argument to `fetch()`. The `method` option is set to `'POST'`, and the `body` option is set to the data you want to send.
The type of data in the `body` option can ... | code_snippets | ||
52e29724-8497-4e82-8b4e-d953021acad6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/http-get-post-put-delete.md | unknown | 7d4df65c-86b3-47bc-b5f2-15f2e67f1693 | 5 | SemanticChunker@1.0.0 | cc2f94a9726015281b2baba8e819147fe6b6d043bd6cf3367e398cbb1424bd35 | [HTTP GET request > HTTP DELETE request]
### HTTP DELETE request
To make a `DELETE` request, you need to set the `method` option to `'DELETE'` in the request options object. A `DELETE` request does not have a body, so the `body` option is omitted in the following example.
```js
fetch('https://jsonplaceholder.typicod... | unknown | unknown | [HTTP GET request > HTTP DELETE request]
### HTTP DELETE request
To make a `DELETE` request, you need to set the `method` option to `'DELETE'` in the request options object. A `DELETE` request does not have a body, so the `body` option is omitted in the following example.
```js
fetch('https://jsonplaceholder.typicod... | [HTTP GET request > HTTP DELETE request]
### HTTP DELETE request
To make a `DELETE` request, you need to set the `method` option to `'DELETE'` in the request options object. A `DELETE` request does not have a body, so the `body` option is omitted in the following example.
```js
fetch('https://jsonplaceholder.typicod... | code_snippets | ||
5a27ede4-91ae-48a2-af49-50219eb3e9bf | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/http-get-post-put-delete.md | unknown | 7d4df65c-86b3-47bc-b5f2-15f2e67f1693 | 0 | SemanticChunker@1.0.0 | 06f3654703faba0a1822da6ccfca2d26710b691dba841c1b15a4121f1503fe9b | ---
title: How can I perform an HTTP request in JavaScript?
shortTitle: HTTP request
language: javascript
tags: [browser]
cover: boat-port
excerpt: Learn how to perform HTTP GET, POST, PUT, and DELETE requests in JavaScript.
listed: true
dateModified: 2024-02-13
---
The **HTTP protocol** is the foundation of data comm... | unknown | unknown | ---
title: How can I perform an HTTP request in JavaScript?
shortTitle: HTTP request
language: javascript
tags: [browser]
cover: boat-port
excerpt: Learn how to perform HTTP GET, POST, PUT, and DELETE requests in JavaScript.
listed: true
dateModified: 2024-02-13
---
The **HTTP protocol** is the foundation of data comm... | ---
title: How can I perform an HTTP request in JavaScript?
shortTitle: HTTP request
language: javascript
tags: [browser]
cover: boat-port
excerpt: Learn how to perform HTTP GET, POST, PUT, and DELETE requests in JavaScript.
listed: true
dateModified: 2024-02-13
---
The **HTTP protocol** is the foundation of data comm... | code_snippets | ||
6ed3a87f-2c6f-4e25-84b4-cb6134142f2a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/http-get-post-put-delete.md | unknown | 7d4df65c-86b3-47bc-b5f2-15f2e67f1693 | 1 | SemanticChunker@1.0.0 | 632648912040dd0d146304d9eef2f796381656c74074ee022b20ab5568f064dd | [Using the Fetch API]
## Using the Fetch API
<baseline-support featureId="fetch">
</baseline-support>
The [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) is a modern replacement for `XMLHttpRequest`. It is a **promise-based** API that allows you to make network requests similar to `XMLHttpReq... | unknown | unknown | [Using the Fetch API]
## Using the Fetch API
<baseline-support featureId="fetch">
</baseline-support>
The [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) is a modern replacement for `XMLHttpRequest`. It is a **promise-based** API that allows you to make network requests similar to `XMLHttpReq... | [Using the Fetch API]
## Using the Fetch API
<baseline-support featureId="fetch">
</baseline-support>
The [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) is a modern replacement for `XMLHttpRequest`. It is a **promise-based** API that allows you to make network requests similar to `XMLHttpReq... | code_snippets | ||
7062c232-e96f-4650-8de4-346dbe39a2b4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/http-get-post-put-delete.md | unknown | 7d4df65c-86b3-47bc-b5f2-15f2e67f1693 | 4 | SemanticChunker@1.0.0 | 89ee577efd1866bbb41c52e8a8c5d99fa079cb09260baae4dea9449c4f0f86dc | [HTTP GET request > HTTP PUT request]
### HTTP PUT request
Similarly to the `POST` request, you can make a `PUT` request by setting the `method` option to `'PUT'` in the request options object. The rest of the request options are the same as for the `POST` request.
```js
fetch('https://jsonplaceholder.typicode.com/p... | unknown | unknown | [HTTP GET request > HTTP PUT request]
### HTTP PUT request
Similarly to the `POST` request, you can make a `PUT` request by setting the `method` option to `'PUT'` in the request options object. The rest of the request options are the same as for the `POST` request.
```js
fetch('https://jsonplaceholder.typicode.com/p... | [HTTP GET request > HTTP PUT request]
### HTTP PUT request
Similarly to the `POST` request, you can make a `PUT` request by setting the `method` option to `'PUT'` in the request options object. The rest of the request options are the same as for the `POST` request.
```js
fetch('https://jsonplaceholder.typicode.com/p... | code_snippets | ||
7e16b240-237a-4a71-8027-20693568e050 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/http-get-post-put-delete.md | unknown | 7d4df65c-86b3-47bc-b5f2-15f2e67f1693 | 9 | SemanticChunker@1.0.0 | bf78f7ba9175348e9e0e0f047e8b892d8489a96cf318736dcbeab62dff0b26c7 | [Using XMLHttpRequest > HTTP PUT request]
### HTTP PUT request
The following example makes a `PUT` request to a given URL using the `XMLHttpRequest` web API. The `data` argument is the data you want to send, and the `callback` function is called with the `responseText` when the request is successful.
```js
const htt... | unknown | unknown | [Using XMLHttpRequest > HTTP PUT request]
### HTTP PUT request
The following example makes a `PUT` request to a given URL using the `XMLHttpRequest` web API. The `data` argument is the data you want to send, and the `callback` function is called with the `responseText` when the request is successful.
```js
const htt... | [Using XMLHttpRequest > HTTP PUT request]
### HTTP PUT request
The following example makes a `PUT` request to a given URL using the `XMLHttpRequest` web API. The `data` argument is the data you want to send, and the `callback` function is called with the `responseText` when the request is successful.
```js
const htt... | code_snippets | ||
848a9eaa-b067-410c-a7cf-bdbd408f226b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/http-get-post-put-delete.md | unknown | 7d4df65c-86b3-47bc-b5f2-15f2e67f1693 | 8 | SemanticChunker@1.0.0 | efa75773a72da8fbc7fe695dc0acc4f5ed05abb79af4d6f4796d48c3b5750e59 | [Using XMLHttpRequest > HTTP POST request]
### HTTP POST request
The following example makes a `POST` request to a given URL using the `XMLHttpRequest` web API. The `data` argument is the data you want to send, and the `callback` function is called with the `responseText` when the request is successful. In order to s... | unknown | unknown | [Using XMLHttpRequest > HTTP POST request]
### HTTP POST request
The following example makes a `POST` request to a given URL using the `XMLHttpRequest` web API. The `data` argument is the data you want to send, and the `callback` function is called with the `responseText` when the request is successful. In order to s... | [Using XMLHttpRequest > HTTP POST request]
### HTTP POST request
The following example makes a `POST` request to a given URL using the `XMLHttpRequest` web API. The `data` argument is the data you want to send, and the `callback` function is called with the `responseText` when the request is successful. In order to s... | code_snippets | ||
94b39478-5396-4fbd-bd47-44e4cfc1725c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/http-get-post-put-delete.md | unknown | 7d4df65c-86b3-47bc-b5f2-15f2e67f1693 | 10 | SemanticChunker@1.0.0 | e503ccbb54bfffa8cd59297e6c40ad1ab8f1cdad433fb47113bac05bbe2dd5a7 | [Using XMLHttpRequest > HTTP DELETE request]
### HTTP DELETE request
The following example makes a `DELETE` request to a given URL using the `XMLHttpRequest` web API. The `callback` function is called with the `responseText` when the request is successful.
```js
const httpDelete = (url, callback, err = console.error... | unknown | unknown | [Using XMLHttpRequest > HTTP DELETE request]
### HTTP DELETE request
The following example makes a `DELETE` request to a given URL using the `XMLHttpRequest` web API. The `callback` function is called with the `responseText` when the request is successful.
```js
const httpDelete = (url, callback, err = console.error... | [Using XMLHttpRequest > HTTP DELETE request]
### HTTP DELETE request
The following example makes a `DELETE` request to a given URL using the `XMLHttpRequest` web API. The `callback` function is called with the `responseText` when the request is successful.
```js
const httpDelete = (url, callback, err = console.error... | code_snippets | ||
b79072fc-f650-4d00-b33e-a5614f5b214e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/http-get-post-put-delete.md | unknown | 7d4df65c-86b3-47bc-b5f2-15f2e67f1693 | 6 | SemanticChunker@1.0.0 | 2921d00e3338293ad90f75208884c722244cc7de7671d4e892f4639455989d74 | [Using the Fetch API > Using XMLHttpRequest]
## Using XMLHttpRequest
<baseline-support featureId="xhr">
</baseline-support>
The `XMLHttpRequest` web API is the **older way** of making HTTP requests in JavaScript. It is not as powerful as the `fetch` API, but it is still widely used and supported in all modern browse... | unknown | unknown | [Using the Fetch API > Using XMLHttpRequest]
## Using XMLHttpRequest
<baseline-support featureId="xhr">
</baseline-support>
The `XMLHttpRequest` web API is the **older way** of making HTTP requests in JavaScript. It is not as powerful as the `fetch` API, but it is still widely used and supported in all modern browse... | [Using the Fetch API > Using XMLHttpRequest]
## Using XMLHttpRequest
<baseline-support featureId="xhr">
</baseline-support>
The `XMLHttpRequest` web API is the **older way** of making HTTP requests in JavaScript. It is not as powerful as the `fetch` API, but it is still widely used and supported in all modern browse... | code_snippets | ||
e795a335-fe41-498d-b4c9-9b3de04030a0 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/http-get-post-put-delete.md | unknown | 7d4df65c-86b3-47bc-b5f2-15f2e67f1693 | 7 | SemanticChunker@1.0.0 | 978ded8dd0cb0f94f293bc861a5a0f7fe8f867a9f760fa9a2b612fcf49781960 | [Using XMLHttpRequest > HTTP GET request]
### HTTP GET request
The following example makes a `GET` request to a given URL using the `XMLHttpRequest` web API. The given `callback` function is called with the `responseText` when the request is successful, and the `err` function is called when an error occurs.
```js
co... | unknown | unknown | [Using XMLHttpRequest > HTTP GET request]
### HTTP GET request
The following example makes a `GET` request to a given URL using the `XMLHttpRequest` web API. The given `callback` function is called with the `responseText` when the request is successful, and the `err` function is called when an error occurs.
```js
co... | [Using XMLHttpRequest > HTTP GET request]
### HTTP GET request
The following example makes a `GET` request to a given URL using the `XMLHttpRequest` web API. The given `callback` function is called with the `responseText` when the request is successful, and the `err` function is called when an error occurs.
```js
co... | code_snippets | ||
22953a31-0c3e-4294-aca5-fa516ef54cf7 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/html-element-test-add-remove-toggle-class.md | unknown | e27d8294-f7f8-434c-98f6-dc7a4ea89fd9 | 2 | SemanticChunker@1.0.0 | 2747b0b988c2436fa4989648a4b75d5169d00089810446867ffb1f182340f308 | [Check if HTML element has a class > Add a class to HTML element]
## Add a class to HTML element
To **add a class to an HTML element**, you can use the `Element.classList` property and the `DOMTokenList.add()` method.
```js
const addClass = (el, className) => el.classList.add(className);
addClass(document.querySele... | unknown | unknown | [Check if HTML element has a class > Add a class to HTML element]
## Add a class to HTML element
To **add a class to an HTML element**, you can use the `Element.classList` property and the `DOMTokenList.add()` method.
```js
const addClass = (el, className) => el.classList.add(className);
addClass(document.querySele... | [Check if HTML element has a class > Add a class to HTML element]
## Add a class to HTML element
To **add a class to an HTML element**, you can use the `Element.classList` property and the `DOMTokenList.add()` method.
```js
const addClass = (el, className) => el.classList.add(className);
addClass(document.querySele... | code_snippets | ||
5df5429c-e0a4-4fb9-a38b-36567dcc512d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/html-element-test-add-remove-toggle-class.md | unknown | e27d8294-f7f8-434c-98f6-dc7a4ea89fd9 | 3 | SemanticChunker@1.0.0 | e4ebc53604b6dc6ba223e6f7f30604e606d506f931afde55d7ae7bbf38a428de | [Check if HTML element has a class > Remove a class from HTML element]
## Remove a class from HTML element
Similarly, **removing a class from an HTML element** can be done the same way, but using the `DOMTokenList.remove()` method, instead.
```js
const removeClass = (el, className) => el.classList.remove(className);... | unknown | unknown | [Check if HTML element has a class > Remove a class from HTML element]
## Remove a class from HTML element
Similarly, **removing a class from an HTML element** can be done the same way, but using the `DOMTokenList.remove()` method, instead.
```js
const removeClass = (el, className) => el.classList.remove(className);... | [Check if HTML element has a class > Remove a class from HTML element]
## Remove a class from HTML element
Similarly, **removing a class from an HTML element** can be done the same way, but using the `DOMTokenList.remove()` method, instead.
```js
const removeClass = (el, className) => el.classList.remove(className);... | code_snippets | ||
6e67a14c-3058-486a-9ae8-48a4ad83e246 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/html-element-test-add-remove-toggle-class.md | unknown | e27d8294-f7f8-434c-98f6-dc7a4ea89fd9 | 4 | SemanticChunker@1.0.0 | d9c82bc7ae577f84c6b50407369fe3bc1e713aff9d146ea51a1fa2573687b17f | [Check if HTML element has a class > Toggle a class for HTML element]
## Toggle a class for HTML element
Finally, if you only need to **switch a class on and off**, you can use the `DOMTokenList.toggle()` method.
```js
const toggleClass = (el, className) => el.classList.toggle(className);
toggleClass(document.query... | unknown | unknown | [Check if HTML element has a class > Toggle a class for HTML element]
## Toggle a class for HTML element
Finally, if you only need to **switch a class on and off**, you can use the `DOMTokenList.toggle()` method.
```js
const toggleClass = (el, className) => el.classList.toggle(className);
toggleClass(document.query... | [Check if HTML element has a class > Toggle a class for HTML element]
## Toggle a class for HTML element
Finally, if you only need to **switch a class on and off**, you can use the `DOMTokenList.toggle()` method.
```js
const toggleClass = (el, className) => el.classList.toggle(className);
toggleClass(document.query... | code_snippets | ||
764fa5c0-fa9e-41e1-8137-2f631469eb27 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/html-element-test-add-remove-toggle-class.md | unknown | e27d8294-f7f8-434c-98f6-dc7a4ea89fd9 | 0 | SemanticChunker@1.0.0 | 7f3aa06963a021277f69d97fe27294b0976f16c5fbddde9d312b552e077ca788 | ---
title: HTML element class manipulation with JavaScript
shortTitle: Check or toggle HTML element class
language: javascript
tags: [browser]
cover: bag-waiting
excerpt: Learn how to work with HTML element classes in JavaScript, from simple class checks to adding, removing and toggling classes.
listed: true
dateModifi... | unknown | unknown | ---
title: HTML element class manipulation with JavaScript
shortTitle: Check or toggle HTML element class
language: javascript
tags: [browser]
cover: bag-waiting
excerpt: Learn how to work with HTML element classes in JavaScript, from simple class checks to adding, removing and toggling classes.
listed: true
dateModifi... | ---
title: HTML element class manipulation with JavaScript
shortTitle: Check or toggle HTML element class
language: javascript
tags: [browser]
cover: bag-waiting
excerpt: Learn how to work with HTML element classes in JavaScript, from simple class checks to adding, removing and toggling classes.
listed: true
dateModifi... | code_snippets | ||
cdd6c15f-0c3a-4687-b247-ff790892fde7 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/html-element-test-add-remove-toggle-class.md | unknown | e27d8294-f7f8-434c-98f6-dc7a4ea89fd9 | 1 | SemanticChunker@1.0.0 | b5fdf9dd7d85dbb36d2a3fce2aaa1870df51cbe948451dab60831320dc401db7 | [Check if HTML element has a class]
## Check if HTML element has a class
To **check if an HTML element has a class**, you can use the `Element.classList` property and the `DOMTokenList.contains()` method.
```js
const hasClass = (el, className) => el.classList.contains(className);
hasClass(document.querySelector('p.... | unknown | unknown | [Check if HTML element has a class]
## Check if HTML element has a class
To **check if an HTML element has a class**, you can use the `Element.classList` property and the `DOMTokenList.contains()` method.
```js
const hasClass = (el, className) => el.classList.contains(className);
hasClass(document.querySelector('p.... | [Check if HTML element has a class]
## Check if HTML element has a class
To **check if an HTML element has a class**, you can use the `Element.classList` property and the `DOMTokenList.contains()` method.
```js
const hasClass = (el, className) => el.classList.contains(className);
hasClass(document.querySelector('p.... | code_snippets | ||
5f0b6b2e-2ae2-4c4c-a757-477621d9b5f6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/iife.md | unknown | 6fc5bb2d-3dab-4663-a030-540e73b6b183 | 1 | SemanticChunker@1.0.0 | 94c6340e3cbd6683db35f4243aeaa241dbbaada1766c1d4adc1ba9122bcba349 | IIFEs are often used to run some code, while keeping it and its variables out of the global scope. They are often criticized for lack of readability and how they are confusing to beginners. Additionally, they started going out of fashion with the rise of JavaScript modules and transpilers, so they might be less and les... | unknown | unknown | IIFEs are often used to run some code, while keeping it and its variables out of the global scope. They are often criticized for lack of readability and how they are confusing to beginners. Additionally, they started going out of fashion with the rise of JavaScript modules and transpilers, so they might be less and les... | IIFEs are often used to run some code, while keeping it and its variables out of the global scope. They are often criticized for lack of readability and how they are confusing to beginners. Additionally, they started going out of fashion with the rise of JavaScript modules and transpilers, so they might be less and les... | code_snippets | ||
701d1c87-eba6-4a17-be7d-7f0e9922ad74 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/iife.md | unknown | 6fc5bb2d-3dab-4663-a030-540e73b6b183 | 0 | SemanticChunker@1.0.0 | d0a55be907230171a7293df167600abb5216e920354acb9265b4e79bd5abc118 | ---
title: What is an IIFE in JavaScript?
shortTitle: IIFE introduction
language: javascript
tags: [function]
cover: tropical-waterfall
excerpt: An Immediately Invoked Function Expression (IIFE) is a JavaScript trick that trips up many developers. Here's what you need to know.
listed: true
dateModified: 2021-06-14
---
... | unknown | unknown | ---
title: What is an IIFE in JavaScript?
shortTitle: IIFE introduction
language: javascript
tags: [function]
cover: tropical-waterfall
excerpt: An Immediately Invoked Function Expression (IIFE) is a JavaScript trick that trips up many developers. Here's what you need to know.
listed: true
dateModified: 2021-06-14
---
... | ---
title: What is an IIFE in JavaScript?
shortTitle: IIFE introduction
language: javascript
tags: [function]
cover: tropical-waterfall
excerpt: An Immediately Invoked Function Expression (IIFE) is a JavaScript trick that trips up many developers. Here's what you need to know.
listed: true
dateModified: 2021-06-14
---
... | code_snippets | ||
0addb3b8-da65-493d-b34c-9b18cb611a6c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/hsl-to-array-or-object.md | unknown | 4547fead-7665-4c51-9893-4a977a6d7643 | 2 | SemanticChunker@1.0.0 | 34e57c953e66174ef680efc6e6229e5e0a70e63b82d1aa8866196e031729f559 | [Convert an `hsl()` color string to an array > Convert an `hsl()` color string to an object]
## Convert an `hsl()` color string to an object
The steps for converting an `hsl()` color string to an **object with the values of each color** are almost identical to the previous approach. The only difference is you need to... | unknown | unknown | [Convert an `hsl()` color string to an array > Convert an `hsl()` color string to an object]
## Convert an `hsl()` color string to an object
The steps for converting an `hsl()` color string to an **object with the values of each color** are almost identical to the previous approach. The only difference is you need to... | [Convert an `hsl()` color string to an array > Convert an `hsl()` color string to an object]
## Convert an `hsl()` color string to an object
The steps for converting an `hsl()` color string to an **object with the values of each color** are almost identical to the previous approach. The only difference is you need to... | code_snippets | ||
7bc2fc69-da27-49d9-8a59-72d8c012178d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/hsl-to-array-or-object.md | unknown | 4547fead-7665-4c51-9893-4a977a6d7643 | 1 | SemanticChunker@1.0.0 | 595db6247bffec39313dd3203781a17a8dcf7f3563a5b3afe85024f529c3aa84 | [Convert an `hsl()` color string to an array]
## Convert an `hsl()` color string to an array
An `hsl()` color string may contain spaces, commas and percentage signs. However, using an appropriate regular expression combined with `String.prototype.match()` allows you to easily extract the numeric values from the strin... | unknown | unknown | [Convert an `hsl()` color string to an array]
## Convert an `hsl()` color string to an array
An `hsl()` color string may contain spaces, commas and percentage signs. However, using an appropriate regular expression combined with `String.prototype.match()` allows you to easily extract the numeric values from the strin... | [Convert an `hsl()` color string to an array]
## Convert an `hsl()` color string to an array
An `hsl()` color string may contain spaces, commas and percentage signs. However, using an appropriate regular expression combined with `String.prototype.match()` allows you to easily extract the numeric values from the strin... | code_snippets | ||
80362476-509a-4993-a82a-2eb8533d016a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/hsl-to-array-or-object.md | unknown | 4547fead-7665-4c51-9893-4a977a6d7643 | 0 | SemanticChunker@1.0.0 | 321a6d9c7c8a75a82627ff8b2b43c80ea8b7288542884cd294ac68f8e34052f8 | ---
title: Convert an HSL color string to a JavaScript array or object
shortTitle: HSL to array or object
language: javascript
tags: [string,regexp]
cover: number-2
excerpt: Easily convert an `hsl()` color string to an array of values or an object with the values of each color.
listed: true
dateModified: 2024-03-07
---... | unknown | unknown | ---
title: Convert an HSL color string to a JavaScript array or object
shortTitle: HSL to array or object
language: javascript
tags: [string,regexp]
cover: number-2
excerpt: Easily convert an `hsl()` color string to an array of values or an object with the values of each color.
listed: true
dateModified: 2024-03-07
---... | ---
title: Convert an HSL color string to a JavaScript array or object
shortTitle: HSL to array or object
language: javascript
tags: [string,regexp]
cover: number-2
excerpt: Easily convert an `hsl()` color string to an array of values or an object with the values of each color.
listed: true
dateModified: 2024-03-07
---... | code_snippets | ||
32a8aff1-4e70-4ff2-bc21-8648a117b97e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/how-to-secure-your-js-code-from-vulnerable-dependencies.md | unknown | 5acb9fba-1f5e-4bb9-b00d-a73dc679ed50 | 5 | SemanticChunker@1.0.0 | 1c1fe96714fdcde6ecb92e96fdedbffb70c8e2b6ce177499a9c2d7dd75025c09 | [Audit dependencies regularly > Monitor for malicious updates]
## Monitor for malicious updates
**Stay informed about new vulnerabilities** and malicious package updates by subscribing to **security advisories** and update your dependencies promptly when patches are released. GitHub provides **automated alerts** for ... | unknown | unknown | [Audit dependencies regularly > Monitor for malicious updates]
## Monitor for malicious updates
**Stay informed about new vulnerabilities** and malicious package updates by subscribing to **security advisories** and update your dependencies promptly when patches are released. GitHub provides **automated alerts** for ... | [Audit dependencies regularly > Monitor for malicious updates]
## Monitor for malicious updates
**Stay informed about new vulnerabilities** and malicious package updates by subscribing to **security advisories** and update your dependencies promptly when patches are released. GitHub provides **automated alerts** for ... | code_snippets | ||
5b179e71-d367-4e5e-9f91-7cd23ced32f9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/how-to-secure-your-js-code-from-vulnerable-dependencies.md | unknown | 5acb9fba-1f5e-4bb9-b00d-a73dc679ed50 | 3 | SemanticChunker@1.0.0 | 4c6c26eedcafaac608a5431789b95547fc4cbeed1ce0fa0750c62496225977f8 | [Audit dependencies regularly > Minimize dependencies]
## Minimize dependencies
**Keep your dependency footprint as small as possible**. Every additional package increases your attack surface. Remove unused dependencies and prefer built-in language features or your own code for simple tasks.
To identify and remove u... | unknown | unknown | [Audit dependencies regularly > Minimize dependencies]
## Minimize dependencies
**Keep your dependency footprint as small as possible**. Every additional package increases your attack surface. Remove unused dependencies and prefer built-in language features or your own code for simple tasks.
To identify and remove u... | [Audit dependencies regularly > Minimize dependencies]
## Minimize dependencies
**Keep your dependency footprint as small as possible**. Every additional package increases your attack surface. Remove unused dependencies and prefer built-in language features or your own code for simple tasks.
To identify and remove u... | code_snippets | ||
6e430626-3813-466b-9c25-0e119d4eb9fc | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/how-to-secure-your-js-code-from-vulnerable-dependencies.md | unknown | 5acb9fba-1f5e-4bb9-b00d-a73dc679ed50 | 4 | SemanticChunker@1.0.0 | d422106b937e4b1cb0d282acee6fd3c4b90bcdabf754ac867c4d2071ca691b9f | [Audit dependencies regularly > Review transitive dependencies]
## Review transitive dependencies
Your direct dependencies may pull in many others. Regularly **inspect your full dependency tree** to spot risky packages. Use:
```shell
npm ls
```
This outputs your project's dependency graph. Look for deprecated, outd... | unknown | unknown | [Audit dependencies regularly > Review transitive dependencies]
## Review transitive dependencies
Your direct dependencies may pull in many others. Regularly **inspect your full dependency tree** to spot risky packages. Use:
```shell
npm ls
```
This outputs your project's dependency graph. Look for deprecated, outd... | [Audit dependencies regularly > Review transitive dependencies]
## Review transitive dependencies
Your direct dependencies may pull in many others. Regularly **inspect your full dependency tree** to spot risky packages. Use:
```shell
npm ls
```
This outputs your project's dependency graph. Look for deprecated, outd... | code_snippets | ||
8493233b-8e84-490d-b775-8df4a5eaaf6a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/how-to-secure-your-js-code-from-vulnerable-dependencies.md | unknown | 5acb9fba-1f5e-4bb9-b00d-a73dc679ed50 | 0 | SemanticChunker@1.0.0 | f9de2bb102ceaac552bb13381d393784c4a3a2209946d6c0e673404313a72f4d | ---
title: How to secure your JavaScript code from vulnerable dependencies
shortTitle: JavaScript dependency security
language: javascript
tags: [webdev,security]
cover: locked-tablet
excerpt: Keep your code, data, and users safe by following these simple tips to secure your JavaScript projects from vulnerable dependen... | unknown | unknown | ---
title: How to secure your JavaScript code from vulnerable dependencies
shortTitle: JavaScript dependency security
language: javascript
tags: [webdev,security]
cover: locked-tablet
excerpt: Keep your code, data, and users safe by following these simple tips to secure your JavaScript projects from vulnerable dependen... | ---
title: How to secure your JavaScript code from vulnerable dependencies
shortTitle: JavaScript dependency security
language: javascript
tags: [webdev,security]
cover: locked-tablet
excerpt: Keep your code, data, and users safe by following these simple tips to secure your JavaScript projects from vulnerable dependen... | code_snippets | ||
95f54ed5-bfd6-42b5-b423-918474d256fb | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/how-to-secure-your-js-code-from-vulnerable-dependencies.md | unknown | 5acb9fba-1f5e-4bb9-b00d-a73dc679ed50 | 6 | SemanticChunker@1.0.0 | fe92459424b6e8b443bab167fadbaf70f6f7316525bd8c635745581837934974 | [Audit dependencies regularly > Closing thoughts]
## Closing thoughts
Securing your JavaScript projects against supply chain attacks is a continuous process. By using **best practices** and **automated tools**, you can significantly reduce your risk. Make these habits part of your standard development workflow to kee... | unknown | unknown | [Audit dependencies regularly > Closing thoughts]
## Closing thoughts
Securing your JavaScript projects against supply chain attacks is a continuous process. By using **best practices** and **automated tools**, you can significantly reduce your risk. Make these habits part of your standard development workflow to kee... | [Audit dependencies regularly > Closing thoughts]
## Closing thoughts
Securing your JavaScript projects against supply chain attacks is a continuous process. By using **best practices** and **automated tools**, you can significantly reduce your risk. Make these habits part of your standard development workflow to kee... | code_snippets | ||
9bc7e520-73a9-40e9-bc3b-9a4ee3d1a4c5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/how-to-secure-your-js-code-from-vulnerable-dependencies.md | unknown | 5acb9fba-1f5e-4bb9-b00d-a73dc679ed50 | 1 | SemanticChunker@1.0.0 | 33f0b1794287da734a3289fb647cd92a9804029f94404f234ea22250cdcbed37 | [Audit dependencies regularly]
# Audit dependencies regularly
Regularly scan your project for **known vulnerabilities** using **automated tools**. The npm CLI provides a built-in auditing command:
```shell
npm audit
```
This will report any security issues in your dependencies. For continuous monitoring, consider i... | unknown | unknown | [Audit dependencies regularly]
# Audit dependencies regularly
Regularly scan your project for **known vulnerabilities** using **automated tools**. The npm CLI provides a built-in auditing command:
```shell
npm audit
```
This will report any security issues in your dependencies. For continuous monitoring, consider i... | [Audit dependencies regularly]
# Audit dependencies regularly
Regularly scan your project for **known vulnerabilities** using **automated tools**. The npm CLI provides a built-in auditing command:
```shell
npm audit
```
This will report any security issues in your dependencies. For continuous monitoring, consider i... | code_snippets | ||
bbd58fe2-24d1-4375-9e68-a37703439787 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/how-to-secure-your-js-code-from-vulnerable-dependencies.md | unknown | 5acb9fba-1f5e-4bb9-b00d-a73dc679ed50 | 2 | SemanticChunker@1.0.0 | 4d594104b9c8a8e2424007fca59897e706482683b238ac19268d921661ee7d5b | [Audit dependencies regularly > Pin dependency versions]
## Pin dependency versions
Avoid surprises from upstream updates by **locking your dependencies to known good versions**. Use a `package-lock.json` file in combination with the `npm ci` command to ensure reproducible builds:
```shell
npm ci
```
It installs ex... | unknown | unknown | [Audit dependencies regularly > Pin dependency versions]
## Pin dependency versions
Avoid surprises from upstream updates by **locking your dependencies to known good versions**. Use a `package-lock.json` file in combination with the `npm ci` command to ensure reproducible builds:
```shell
npm ci
```
It installs ex... | [Audit dependencies regularly > Pin dependency versions]
## Pin dependency versions
Avoid surprises from upstream updates by **locking your dependencies to known good versions**. Use a `package-lock.json` file in combination with the `npm ci` command to ensure reproducible builds:
```shell
npm ci
```
It installs ex... | code_snippets | ||
4488e433-718a-4949-b375-6d06d311cb9c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-array-with-range.md | unknown | 4e00ab86-9a47-4d69-8e7c-2cc9a0b4fb56 | 0 | SemanticChunker@1.0.0 | b5a5653a0b72d6a8439e28f17c723d400dea92f33603061e34911b43a5a17862 | ---
title: Initialize a JavaScript array with a given numeric range
shortTitle: Initialize array with range
language: javascript
tags: [array]
cover: spanish-resort
excerpt: Learn how to create an inclusive array with numbers in a range, using a common `step` difference.
listed: true
dateModified: 2023-12-25
---
[Arra... | unknown | unknown | ---
title: Initialize a JavaScript array with a given numeric range
shortTitle: Initialize array with range
language: javascript
tags: [array]
cover: spanish-resort
excerpt: Learn how to create an inclusive array with numbers in a range, using a common `step` difference.
listed: true
dateModified: 2023-12-25
---
[Arra... | ---
title: Initialize a JavaScript array with a given numeric range
shortTitle: Initialize array with range
language: javascript
tags: [array]
cover: spanish-resort
excerpt: Learn how to create an inclusive array with numbers in a range, using a common `step` difference.
listed: true
dateModified: 2023-12-25
---
[Arra... | code_snippets | ||
a957f6e2-2768-44c9-b967-aca98127368b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-array-with-range.md | unknown | 4e00ab86-9a47-4d69-8e7c-2cc9a0b4fb56 | 2 | SemanticChunker@1.0.0 | 5d7da00fb9971e6fb0834b8a0e3401f41495ea9130af630e12bfb8830389e51c | [Initialize array with a numeric range > Initialize array with a reversed numeric range]
## Initialize array with a reversed numeric range
If you want a reversed range, you might be tempted to use `Array.prototype.reverse()` on the result of the previous snippet. However, this is relatively inefficient, as it require... | unknown | unknown | [Initialize array with a numeric range > Initialize array with a reversed numeric range]
## Initialize array with a reversed numeric range
If you want a reversed range, you might be tempted to use `Array.prototype.reverse()` on the result of the previous snippet. However, this is relatively inefficient, as it require... | [Initialize array with a numeric range > Initialize array with a reversed numeric range]
## Initialize array with a reversed numeric range
If you want a reversed range, you might be tempted to use `Array.prototype.reverse()` on the result of the previous snippet. However, this is relatively inefficient, as it require... | code_snippets | ||
abc4a000-5882-4920-bb87-97fccc07b36c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-array-with-range.md | unknown | 4e00ab86-9a47-4d69-8e7c-2cc9a0b4fb56 | 1 | SemanticChunker@1.0.0 | fdd3e45ac51bda8d01b3cff6e1c3e60c3333d10bee30625bb2fcde544d53d25c | [Initialize array with a numeric range]
## Initialize array with a numeric range
We can use `Array.from()` for the purpose of creating a new array. We need to know the `length` of the array beforehand, which can be calculated from the range of numbers we want to include.
The general formula for the `length` of the a... | unknown | unknown | [Initialize array with a numeric range]
## Initialize array with a numeric range
We can use `Array.from()` for the purpose of creating a new array. We need to know the `length` of the array beforehand, which can be calculated from the range of numbers we want to include.
The general formula for the `length` of the a... | [Initialize array with a numeric range]
## Initialize array with a numeric range
We can use `Array.from()` for the purpose of creating a new array. We need to know the `length` of the array beforehand, which can be calculated from the range of numbers we want to include.
The general formula for the `length` of the a... | code_snippets | ||
e6b37dcf-8e2d-4755-be6e-56be98768138 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-array-with-range.md | unknown | 4e00ab86-9a47-4d69-8e7c-2cc9a0b4fb56 | 3 | SemanticChunker@1.0.0 | ba4c4b2efc6a2d1c9d0b87bb3a4474a31c803107fdcf8f524a4c9a2945899046 | [Initialize array with a numeric range > Generalized `range()` function, matching Python's signature]
## Generalized `range()` function, matching Python's signature
Having two functions that serve slightly different purposes is not uncommon, but we can generalize the solution to **infer the correct behavior based on ... | unknown | unknown | [Initialize array with a numeric range > Generalized `range()` function, matching Python's signature]
## Generalized `range()` function, matching Python's signature
Having two functions that serve slightly different purposes is not uncommon, but we can generalize the solution to **infer the correct behavior based on ... | [Initialize array with a numeric range > Generalized `range()` function, matching Python's signature]
## Generalized `range()` function, matching Python's signature
Having two functions that serve slightly different purposes is not uncommon, but we can generalize the solution to **infer the correct behavior based on ... | code_snippets | ||
24d41a31-dae9-4e1e-8abe-56d881459b91 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-array-with-values.md | unknown | 8ecefee4-5b6f-49e1-ae81-9c73a4acf320 | 0 | SemanticChunker@1.0.0 | 3a66498c5061d8cab3521a819811bd0fc603f828acdf9060af70867fee51c4a2 | ---
title: Initialize a JavaScript array with the specified values
shortTitle: Initialize array with values
language: javascript
tags: [array]
cover: flower-portrait-1
excerpt: Initialize and fill a JavaScript array with the specified values, quickly and easily.
listed: true
dateModified: 2023-12-26
---
Oftentimes, yo... | unknown | unknown | ---
title: Initialize a JavaScript array with the specified values
shortTitle: Initialize array with values
language: javascript
tags: [array]
cover: flower-portrait-1
excerpt: Initialize and fill a JavaScript array with the specified values, quickly and easily.
listed: true
dateModified: 2023-12-26
---
Oftentimes, yo... | ---
title: Initialize a JavaScript array with the specified values
shortTitle: Initialize array with values
language: javascript
tags: [array]
cover: flower-portrait-1
excerpt: Initialize and fill a JavaScript array with the specified values, quickly and easily.
listed: true
dateModified: 2023-12-26
---
Oftentimes, yo... | code_snippets | ||
9f5dc5ab-65f0-4671-8773-a9235ab7d101 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-array-with-values.md | unknown | 8ecefee4-5b6f-49e1-ae81-9c73a4acf320 | 2 | SemanticChunker@1.0.0 | 186a02b748ac086ed883892080f1c9bd0f75b9744893cbae1e1491dff8b8fefb | [Initialize an array with the specified value > Initialize an array with multiple values]
## Initialize an array with multiple values
A more complex scenario is to initialize an array with **multiple values**. Supplying an array of values is undesirable, as the value we want might be in itself the array. Instead, we ... | unknown | unknown | [Initialize an array with the specified value > Initialize an array with multiple values]
## Initialize an array with multiple values
A more complex scenario is to initialize an array with **multiple values**. Supplying an array of values is undesirable, as the value we want might be in itself the array. Instead, we ... | [Initialize an array with the specified value > Initialize an array with multiple values]
## Initialize an array with multiple values
A more complex scenario is to initialize an array with **multiple values**. Supplying an array of values is undesirable, as the value we want might be in itself the array. Instead, we ... | code_snippets | ||
a7ba1605-fea8-4539-aba2-e63c4d15b037 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-array-with-values.md | unknown | 8ecefee4-5b6f-49e1-ae81-9c73a4acf320 | 1 | SemanticChunker@1.0.0 | f1a19157a6060c712bd798ddb1feefbd954a75f592371adb2dd5eb35bf2b8af3 | [Initialize an array with the specified value]
## Initialize an array with the specified value
The simplest and most common scenario is to initialize an array with the s**ame value for all items**. We can use the `Array()` constructor to create an array of the desired length and then use `Array.prototype.fill()` to f... | unknown | unknown | [Initialize an array with the specified value]
## Initialize an array with the specified value
The simplest and most common scenario is to initialize an array with the s**ame value for all items**. We can use the `Array()` constructor to create an array of the desired length and then use `Array.prototype.fill()` to f... | [Initialize an array with the specified value]
## Initialize an array with the specified value
The simplest and most common scenario is to initialize an array with the s**ame value for all items**. We can use the `Array()` constructor to create an array of the desired length and then use `Array.prototype.fill()` to f... | code_snippets | ||
0cb543c5-93ca-4f7a-b296-bf3faa7a67fa | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-2d-array.md | unknown | 6d7c6ddd-5b0b-4c47-9019-2a87c791b6ef | 1 | SemanticChunker@1.0.0 | e999d553e84253655220061bc7e8a9566170cdfd905574ba3daef3d3e9883ec7 | [Initialize a 2D array with a specific value]
## Initialize a 2D array with a specific value
Given a **width** and **height**, you can create a 2D array and fill it with a specific value. Use `Array.from()` and `Array.prototype.map()` to generate rows equal to `height` where each row is an array of size `width`. Use ... | unknown | unknown | [Initialize a 2D array with a specific value]
## Initialize a 2D array with a specific value
Given a **width** and **height**, you can create a 2D array and fill it with a specific value. Use `Array.from()` and `Array.prototype.map()` to generate rows equal to `height` where each row is an array of size `width`. Use ... | [Initialize a 2D array with a specific value]
## Initialize a 2D array with a specific value
Given a **width** and **height**, you can create a 2D array and fill it with a specific value. Use `Array.from()` and `Array.prototype.map()` to generate rows equal to `height` where each row is an array of size `width`. Use ... | code_snippets | ||
16651f0e-61ae-4062-afe2-fc45eb6fcbab | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-2d-array.md | unknown | 6d7c6ddd-5b0b-4c47-9019-2a87c791b6ef | 4 | SemanticChunker@1.0.0 | 05b83797491323784577a916cbd127bfefb88a00843a46bdf402f76a710f66cd | [Initialize a 2D array with a specific value > Initialize a skewed 2D array]
## Initialize a skewed 2D array
**Skewed 2D arrays** are arrays where the length of each row is not the same. A simple example would be a triangle where the length of each row is equal to its index. In this case, we can replace the numeric w... | unknown | unknown | [Initialize a 2D array with a specific value > Initialize a skewed 2D array]
## Initialize a skewed 2D array
**Skewed 2D arrays** are arrays where the length of each row is not the same. A simple example would be a triangle where the length of each row is equal to its index. In this case, we can replace the numeric w... | [Initialize a 2D array with a specific value > Initialize a skewed 2D array]
## Initialize a skewed 2D array
**Skewed 2D arrays** are arrays where the length of each row is not the same. A simple example would be a triangle where the length of each row is equal to its index. In this case, we can replace the numeric w... | code_snippets | ||
35c0dc05-d092-4386-891a-885e24b932f3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-2d-array.md | unknown | 6d7c6ddd-5b0b-4c47-9019-2a87c791b6ef | 3 | SemanticChunker@1.0.0 | 79447f49c58c976477f2032d102e969f15057f5323eb9bd71911ac2d4571500d | [Initialize a 2D array with a specific value > Initialize a 2D array using a map function]
## Initialize a 2D array using a map function
A more complex scenario might involve initializing a 2D array with a **sequence of generated values**. For example, you might want to generate a 2D array of coordinates for a grid. ... | unknown | unknown | [Initialize a 2D array with a specific value > Initialize a 2D array using a map function]
## Initialize a 2D array using a map function
A more complex scenario might involve initializing a 2D array with a **sequence of generated values**. For example, you might want to generate a 2D array of coordinates for a grid. ... | [Initialize a 2D array with a specific value > Initialize a 2D array using a map function]
## Initialize a 2D array using a map function
A more complex scenario might involve initializing a 2D array with a **sequence of generated values**. For example, you might want to generate a 2D array of coordinates for a grid. ... | code_snippets | ||
96c8aa86-041f-4e30-aa84-40b03bd6e962 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-2d-array.md | unknown | 6d7c6ddd-5b0b-4c47-9019-2a87c791b6ef | 2 | SemanticChunker@1.0.0 | 78bfbcf46fc181cb271bac3144ca4b7cbef0e016dce62e03b548fd41eb864952 | [Initialize a 2D array with a specific value > Initialize n-dimensional array with a specific value]
### Initialize n-dimensional array with a specific value
A more generic version of the above snippet can be used to initialize an **n-dimensional array** with a specific value. The technique at its core is the same, e... | unknown | unknown | [Initialize a 2D array with a specific value > Initialize n-dimensional array with a specific value]
### Initialize n-dimensional array with a specific value
A more generic version of the above snippet can be used to initialize an **n-dimensional array** with a specific value. The technique at its core is the same, e... | [Initialize a 2D array with a specific value > Initialize n-dimensional array with a specific value]
### Initialize n-dimensional array with a specific value
A more generic version of the above snippet can be used to initialize an **n-dimensional array** with a specific value. The technique at its core is the same, e... | code_snippets | ||
da0c29b2-b6fa-4629-893f-e7a8a3def7e9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-2d-array.md | unknown | 6d7c6ddd-5b0b-4c47-9019-2a87c791b6ef | 0 | SemanticChunker@1.0.0 | 933782c5da1bac23fc621f42c356cfab55e771e7c71a3b7bfd212d4f2739da0d | ---
title: How can I initialize 2D array in JavaScript?
shortTitle: Initialize 2D array
language: javascript
tags: [array,recursion]
cover: cloudy-rock-formation
excerpt: Learn how to initialize a 2D array in JavaScript in a handful of different ways.
listed: true
dateModified: 2023-12-27
---
**2D arrays**, also known... | unknown | unknown | ---
title: How can I initialize 2D array in JavaScript?
shortTitle: Initialize 2D array
language: javascript
tags: [array,recursion]
cover: cloudy-rock-formation
excerpt: Learn how to initialize a 2D array in JavaScript in a handful of different ways.
listed: true
dateModified: 2023-12-27
---
**2D arrays**, also known... | ---
title: How can I initialize 2D array in JavaScript?
shortTitle: Initialize 2D array
language: javascript
tags: [array,recursion]
cover: cloudy-rock-formation
excerpt: Learn how to initialize a 2D array in JavaScript in a handful of different ways.
listed: true
dateModified: 2023-12-27
---
**2D arrays**, also known... | code_snippets | ||
2bd883ce-0b99-4071-8d23-b3d782755b77 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-array-with-generated-sequence.md | unknown | 2e1c95c0-38e8-4f8d-b149-340e9788d9d6 | 0 | SemanticChunker@1.0.0 | b04f1175005d1678d017bbfd159f1f2280d1f19091c9307e564d040dc5df02c3 | ---
title: Initialize a JavaScript array with a sequence of generated values
shortTitle: Initialize array with generated sequence
language: javascript
tags: [array, generator]
cover: neon-desk-2
excerpt: Ever wanted to initialize an array with a sequence of generated values? Here's a few ways to do it.
listed: true
dat... | unknown | unknown | ---
title: Initialize a JavaScript array with a sequence of generated values
shortTitle: Initialize array with generated sequence
language: javascript
tags: [array, generator]
cover: neon-desk-2
excerpt: Ever wanted to initialize an array with a sequence of generated values? Here's a few ways to do it.
listed: true
dat... | ---
title: Initialize a JavaScript array with a sequence of generated values
shortTitle: Initialize array with generated sequence
language: javascript
tags: [array, generator]
cover: neon-desk-2
excerpt: Ever wanted to initialize an array with a sequence of generated values? Here's a few ways to do it.
listed: true
dat... | code_snippets | ||
4c841f75-0fb6-47f0-aaa8-d1d4f9b46b4a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-array-with-generated-sequence.md | unknown | 2e1c95c0-38e8-4f8d-b149-340e9788d9d6 | 4 | SemanticChunker@1.0.0 | 1140b16f33d86110f61b5ba25ebc3ed347b4bacdd80d2c8fa877562cba591f92 | [Initialize an array using a map function > Lazy initialization]
## Lazy initialization
As a side note, some of these operations can be time-consuming and memory-intensive. Oftentimes you may not need the entire array to be initialized at once. In these cases, you can use a **generator function** to lazily initialize... | unknown | unknown | [Initialize an array using a map function > Lazy initialization]
## Lazy initialization
As a side note, some of these operations can be time-consuming and memory-intensive. Oftentimes you may not need the entire array to be initialized at once. In these cases, you can use a **generator function** to lazily initialize... | [Initialize an array using a map function > Lazy initialization]
## Lazy initialization
As a side note, some of these operations can be time-consuming and memory-intensive. Oftentimes you may not need the entire array to be initialized at once. In these cases, you can use a **generator function** to lazily initialize... | code_snippets | ||
74eda323-9f36-4e8f-b34a-560edfe005a3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-array-with-generated-sequence.md | unknown | 2e1c95c0-38e8-4f8d-b149-340e9788d9d6 | 2 | SemanticChunker@1.0.0 | 418b23c85a180db9daf8567b825a5b69a4ebef3ec7e56410bce5867738ed5501 | [Initialize an array using a map function > Initialize an array while a condition is met]
## Initialize an array while a condition is met
The previous code snippet assumed that the **length** of the array to be created is **known in advance**. But what if you want to initialize an array **while a condition is met**? ... | unknown | unknown | [Initialize an array using a map function > Initialize an array while a condition is met]
## Initialize an array while a condition is met
The previous code snippet assumed that the **length** of the array to be created is **known in advance**. But what if you want to initialize an array **while a condition is met**? ... | [Initialize an array using a map function > Initialize an array while a condition is met]
## Initialize an array while a condition is met
The previous code snippet assumed that the **length** of the array to be created is **known in advance**. But what if you want to initialize an array **while a condition is met**? ... | code_snippets | ||
8269229c-421d-45e0-b97d-3e511b71f269 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-array-with-generated-sequence.md | unknown | 2e1c95c0-38e8-4f8d-b149-340e9788d9d6 | 3 | SemanticChunker@1.0.0 | 075306527392e47eff6bed6f34701424f10197ed588cb48359aa1dea07e5557d | [Initialize an array using a map function > Initialize an array using an iterator function & a seed value]
## Initialize an array using an iterator function & a seed value
Ramda's [`unfold()`](https://ramdajs.com/docs/#unfold) function provides another unique way to initialize an array. It accepts an initial **seed v... | unknown | unknown | [Initialize an array using a map function > Initialize an array using an iterator function & a seed value]
## Initialize an array using an iterator function & a seed value
Ramda's [`unfold()`](https://ramdajs.com/docs/#unfold) function provides another unique way to initialize an array. It accepts an initial **seed v... | [Initialize an array using a map function > Initialize an array using an iterator function & a seed value]
## Initialize an array using an iterator function & a seed value
Ramda's [`unfold()`](https://ramdajs.com/docs/#unfold) function provides another unique way to initialize an array. It accepts an initial **seed v... | code_snippets | ||
ef5314b5-d316-43b7-8074-7390703ae315 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/initialize-array-with-generated-sequence.md | unknown | 2e1c95c0-38e8-4f8d-b149-340e9788d9d6 | 1 | SemanticChunker@1.0.0 | b1362929a734c36602ba2ee86967fe3b644476445a3707810ef048f6b0e1f38f | [Initialize an array using a map function]
## Initialize an array using a map function
At the most basic level, you can use the `Array()` constructor and `Array.prototype.map()` to initialize an array with a sequence of values. As the `Array()` constructor results in an **array of empty slots**, you may need to use `... | unknown | unknown | [Initialize an array using a map function]
## Initialize an array using a map function
At the most basic level, you can use the `Array()` constructor and `Array.prototype.map()` to initialize an array with a sequence of values. As the `Array()` constructor results in an **array of empty slots**, you may need to use `... | [Initialize an array using a map function]
## Initialize an array using a map function
At the most basic level, you can use the `Array()` constructor and `Array.prototype.map()` to initialize an array with a sequence of values. As the `Array()` constructor results in an **array of empty slots**, you may need to use `... | code_snippets | ||
65c57d5a-16e6-4ad5-861b-84633adc08a3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/insertion-index-in-sorted-array.md | unknown | 9aa80379-5eea-46a8-95fb-d2aee0096ac6 | 1 | SemanticChunker@1.0.0 | 5a1ad467f53fde480a62ce7b93132f52c47bd8d75b4519f13f1f20316c406467 | [Insertion index in sorted array]
## Insertion index in sorted array
To find the **lowest insertion index** of an element in a sorted array, you can use `Array.prototype.findIndex()` to find the appropriate index where the element should be inserted.
```js
const insertionIndex = (arr, n) => {
const isDescending = a... | unknown | unknown | [Insertion index in sorted array]
## Insertion index in sorted array
To find the **lowest insertion index** of an element in a sorted array, you can use `Array.prototype.findIndex()` to find the appropriate index where the element should be inserted.
```js
const insertionIndex = (arr, n) => {
const isDescending = a... | [Insertion index in sorted array]
## Insertion index in sorted array
To find the **lowest insertion index** of an element in a sorted array, you can use `Array.prototype.findIndex()` to find the appropriate index where the element should be inserted.
```js
const insertionIndex = (arr, n) => {
const isDescending = a... | code_snippets | ||
6e745877-a040-4cd9-b46c-f0abe1c9816b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/insertion-index-in-sorted-array.md | unknown | 9aa80379-5eea-46a8-95fb-d2aee0096ac6 | 2 | SemanticChunker@1.0.0 | 9874e6215e8414144aa928ecbae29d5fc169e4ca10d78de4bfb0ea7bf6319f6c | [Insertion index in sorted array > Using a comparator function to determine the insertion index]
## Using a comparator function to determine the insertion index
For more complex data, you might need a **comparator function** to determine the insertion index. For example, if you have an **array of objects**, you might... | unknown | unknown | [Insertion index in sorted array > Using a comparator function to determine the insertion index]
## Using a comparator function to determine the insertion index
For more complex data, you might need a **comparator function** to determine the insertion index. For example, if you have an **array of objects**, you might... | [Insertion index in sorted array > Using a comparator function to determine the insertion index]
## Using a comparator function to determine the insertion index
For more complex data, you might need a **comparator function** to determine the insertion index. For example, if you have an **array of objects**, you might... | code_snippets | ||
99f8039d-2502-4f7d-ad86-6f5b720b2569 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/insertion-index-in-sorted-array.md | unknown | 9aa80379-5eea-46a8-95fb-d2aee0096ac6 | 0 | SemanticChunker@1.0.0 | 2c2810917a2b52587f2e598628fe8443dbc82b46a0fef8e22244810817e5362c | ---
title: How can I find the insertion index of an element in a sorted JavaScript array?
shortTitle: Insertion index in sorted array
language: javascript
tags: [array,math]
cover: apples
excerpt: Given a sorted array, find the correct index to insert a given value.
listed: true
dateModified: 2024-01-02
---
A **sorted... | unknown | unknown | ---
title: How can I find the insertion index of an element in a sorted JavaScript array?
shortTitle: Insertion index in sorted array
language: javascript
tags: [array,math]
cover: apples
excerpt: Given a sorted array, find the correct index to insert a given value.
listed: true
dateModified: 2024-01-02
---
A **sorted... | ---
title: How can I find the insertion index of an element in a sorted JavaScript array?
shortTitle: Insertion index in sorted array
language: javascript
tags: [array,math]
cover: apples
excerpt: Given a sorted array, find the correct index to insert a given value.
listed: true
dateModified: 2024-01-02
---
A **sorted... | code_snippets | ||
5f07e1b4-91be-4d1d-af4c-835e6472655e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/inject-css.md | unknown | ca4172c5-ec66-4df2-9126-7e5508874619 | 0 | SemanticChunker@1.0.0 | 5d9e5409a097adc50d96a1ff594b32388f8a022ab52243e7ff8b006cef41f80d | ---
title: How can I inject CSS into a web page using JavaScript?
shortTitle: Inject CSS
language: javascript
tags: [browser,css]
cover: dark-leaves-5
excerpt: Injecting CSS into a page via JavaScript is pretty easy, if you know how to leverage the DOM.
listed: true
dateModified: 2024-02-09
---
I've often found myself... | unknown | unknown | ---
title: How can I inject CSS into a web page using JavaScript?
shortTitle: Inject CSS
language: javascript
tags: [browser,css]
cover: dark-leaves-5
excerpt: Injecting CSS into a page via JavaScript is pretty easy, if you know how to leverage the DOM.
listed: true
dateModified: 2024-02-09
---
I've often found myself... | ---
title: How can I inject CSS into a web page using JavaScript?
shortTitle: Inject CSS
language: javascript
tags: [browser,css]
cover: dark-leaves-5
excerpt: Injecting CSS into a page via JavaScript is pretty easy, if you know how to leverage the DOM.
listed: true
dateModified: 2024-02-09
---
I've often found myself... | code_snippets | ||
12ddaf03-b5e1-40c4-86f4-eb36c3ef60a0 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/index-of-substrings.md | unknown | f373ad3e-4fba-4e37-8d7b-42c492bfa3b5 | 0 | SemanticChunker@1.0.0 | 4990e6c693696fe3f4a416f267fdc66dd0cb591222411a2bbaceea2fa414ee9f | ---
title: Find all indexes of a substring in a JavaScript string
shortTitle: All indexes of substring
language: javascript
tags: [string,generator]
cover: armchair-in-yellow
excerpt: Create a generator function that finds all the indexes of a substring in a given string.
listed: true
dateModified: 2024-03-10
---
Find... | unknown | unknown | ---
title: Find all indexes of a substring in a JavaScript string
shortTitle: All indexes of substring
language: javascript
tags: [string,generator]
cover: armchair-in-yellow
excerpt: Create a generator function that finds all the indexes of a substring in a given string.
listed: true
dateModified: 2024-03-10
---
Find... | ---
title: Find all indexes of a substring in a JavaScript string
shortTitle: All indexes of substring
language: javascript
tags: [string,generator]
cover: armchair-in-yellow
excerpt: Create a generator function that finds all the indexes of a substring in a given string.
listed: true
dateModified: 2024-03-10
---
Find... | code_snippets | ||
58e5dc77-c80f-423a-a312-9982c9e8c977 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/index-for-of-loop.md | unknown | ccedf5d5-7583-4a8c-ada0-b81b3e8511b5 | 0 | SemanticChunker@1.0.0 | 926dbdb08a060d8b039be77357e4c9f22e6033b59e3fca3b23d3c5e89e56c7dc | ---
title: Get the index of an array item in a JavaScript for...of loop
shortTitle: Array index in for...of loops
language: javascript
tags: [array,iterator]
cover: cave-view
excerpt: Did you know you can get the index of an array item in a JavaScript for...of loop? Learn how with this bite-sized tip.
listed: true
date... | unknown | unknown | ---
title: Get the index of an array item in a JavaScript for...of loop
shortTitle: Array index in for...of loops
language: javascript
tags: [array,iterator]
cover: cave-view
excerpt: Did you know you can get the index of an array item in a JavaScript for...of loop? Learn how with this bite-sized tip.
listed: true
date... | ---
title: Get the index of an array item in a JavaScript for...of loop
shortTitle: Array index in for...of loops
language: javascript
tags: [array,iterator]
cover: cave-view
excerpt: Did you know you can get the index of an array item in a JavaScript for...of loop? Learn how with this bite-sized tip.
listed: true
date... | code_snippets | ||
05d7d210-085b-4876-82d7-0ae7a6617bd1 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/indexed-object-collections.md | unknown | 337ee459-a922-4558-a083-88a81a53fd6b | 2 | SemanticChunker@1.0.0 | 8adc8774e911b886bd13cd8745c8df5c6dec5d1ba3113ffcb63a49e96ec03a4c | [Indexes]
In this example, we have a collection of objects, each with a unique `id` field. We use a `Map` to create an index on the `id` property. When we **add an object** to the collection, we also **add it to the index**. When we want to retrieve an object by `id`, we can **look it up in the index**, which is much ... | unknown | unknown | [Indexes]
In this example, we have a collection of objects, each with a unique `id` field. We use a `Map` to create an index on the `id` property. When we **add an object** to the collection, we also **add it to the index**. When we want to retrieve an object by `id`, we can **look it up in the index**, which is much ... | [Indexes]
In this example, we have a collection of objects, each with a unique `id` field. We use a `Map` to create an index on the `id` property. When we **add an object** to the collection, we also **add it to the index**. When we want to retrieve an object by `id`, we can **look it up in the index**, which is much ... | code_snippets | ||
1713db63-2434-4ac0-a537-a4bb19c78e03 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/indexed-object-collections.md | unknown | 337ee459-a922-4558-a083-88a81a53fd6b | 4 | SemanticChunker@1.0.0 | fc4c9a5293a0e34cd661622009a683e11d0c32390667b355f90e1bc4e995d7a1 | [Indexes > Cardinality]
```
While this example isn't perfect, it goes to show you how cardinality works. When we create an index, we essentially **group objects by a property**. The higher the cardinality of the property, the more groups we have. More groups means that, when we search for a specific object, we have t... | unknown | unknown | [Indexes > Cardinality]
```
While this example isn't perfect, it goes to show you how cardinality works. When we create an index, we essentially **group objects by a property**. The higher the cardinality of the property, the more groups we have. More groups means that, when we search for a specific object, we have t... | [Indexes > Cardinality]
```
While this example isn't perfect, it goes to show you how cardinality works. When we create an index, we essentially **group objects by a property**. The higher the cardinality of the property, the more groups we have. More groups means that, when we search for a specific object, we have t... | code_snippets | ||
3a27d8f8-2338-462a-8b17-d6e78f02097d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/indexed-object-collections.md | unknown | 337ee459-a922-4558-a083-88a81a53fd6b | 11 | SemanticChunker@1.0.0 | c10556c83ed5de57b04dd733cdda9bd6dab1781675705c5d911938dd6053388c | [Indexes > A full implementation]
collection.createIndex(['name', 'status'], {
unique: true,
name: 'name_status',
});
collection.createIndex(['status'], { unique: false, name: 'status' });
collection.createIndex(['origin'], { unique: false, name: 'origin' });
collection.find({ name: 'Lime' });
// Found matching in... | unknown | unknown | [Indexes > A full implementation]
collection.createIndex(['name', 'status'], {
unique: true,
name: 'name_status',
});
collection.createIndex(['status'], { unique: false, name: 'status' });
collection.createIndex(['origin'], { unique: false, name: 'origin' });
collection.find({ name: 'Lime' });
// Found matching in... | [Indexes > A full implementation]
collection.createIndex(['name', 'status'], {
unique: true,
name: 'name_status',
});
collection.createIndex(['status'], { unique: false, name: 'status' });
collection.createIndex(['origin'], { unique: false, name: 'origin' });
collection.find({ name: 'Lime' });
// Found matching in... | code_snippets | ||
4c8028de-6500-40e4-aa31-8a1b411c332d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/indexed-object-collections.md | unknown | 337ee459-a922-4558-a083-88a81a53fd6b | 8 | SemanticChunker@1.0.0 | 7fca121aec57e49a50fe59232231e3b70fa70a00c88415349dd916b5fa4e341a | [Indexes > A full implementation]
```
```js title="objectCollection.js"
import ObjectIndex from './objectIndex.js';
import { randomUUID } from 'crypto';
class ObjectCollection {
#indexes = new Map();
constructor() {
this.createIndex(['_id'], { unique: true, name: '_id_' });
}
get indexes() {
return [...this.... | unknown | unknown | [Indexes > A full implementation]
```
```js title="objectCollection.js"
import ObjectIndex from './objectIndex.js';
import { randomUUID } from 'crypto';
class ObjectCollection {
#indexes = new Map();
constructor() {
this.createIndex(['_id'], { unique: true, name: '_id_' });
}
get indexes() {
return [...this.... | [Indexes > A full implementation]
```
```js title="objectCollection.js"
import ObjectIndex from './objectIndex.js';
import { randomUUID } from 'crypto';
class ObjectCollection {
#indexes = new Map();
constructor() {
this.createIndex(['_id'], { unique: true, name: '_id_' });
}
get indexes() {
return [...this.... | code_snippets | ||
4e7e71ab-bc5d-4990-9e81-2b022c92d840 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/indexed-object-collections.md | unknown | 337ee459-a922-4558-a083-88a81a53fd6b | 6 | SemanticChunker@1.0.0 | b85f1c564501d6646082d378d514d55d0d5e7ea2731ec863a5ef43e2610e73dc | [Indexes > A full implementation]
## A full implementation
Having explored the nuances of indexes and cardinality, let's look at an extensive example of an implementation of indexes object collections, allowing you to create an **arbitrary number of indexes with any number of keys**. These indexes can be marked as `u... | unknown | unknown | [Indexes > A full implementation]
## A full implementation
Having explored the nuances of indexes and cardinality, let's look at an extensive example of an implementation of indexes object collections, allowing you to create an **arbitrary number of indexes with any number of keys**. These indexes can be marked as `u... | [Indexes > A full implementation]
## A full implementation
Having explored the nuances of indexes and cardinality, let's look at an extensive example of an implementation of indexes object collections, allowing you to create an **arbitrary number of indexes with any number of keys**. These indexes can be marked as `u... | code_snippets | ||
501785b5-3f85-4fc9-b4a2-00fc62107cc2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/indexed-object-collections.md | unknown | 337ee459-a922-4558-a083-88a81a53fd6b | 12 | SemanticChunker@1.0.0 | 587b2669593d8e6200941e4861e13b1195871629e9a3a5d02df7454a51b9bc57 | [Indexes > A full implementation]
collection.find({ origin: 'Spain', name: 'Lime' });
// Found matching indexes:
// - name_status [name] (partial)
// - origin [origin] (full)
// Using index 'origin' [origin] (full)
// Filtering 12 results with remaining keys: name
//
// [
// {
// name: 'Lime',
// status: 'fresh',
// o... | unknown | unknown | [Indexes > A full implementation]
collection.find({ origin: 'Spain', name: 'Lime' });
// Found matching indexes:
// - name_status [name] (partial)
// - origin [origin] (full)
// Using index 'origin' [origin] (full)
// Filtering 12 results with remaining keys: name
//
// [
// {
// name: 'Lime',
// status: 'fresh',
// o... | [Indexes > A full implementation]
collection.find({ origin: 'Spain', name: 'Lime' });
// Found matching indexes:
// - name_status [name] (partial)
// - origin [origin] (full)
// Using index 'origin' [origin] (full)
// Filtering 12 results with remaining keys: name
//
// [
// {
// name: 'Lime',
// status: 'fresh',
// o... | code_snippets | ||
562e4941-9400-4415-aada-c5226d4d9f9e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/indexed-object-collections.md | unknown | 337ee459-a922-4558-a083-88a81a53fd6b | 7 | SemanticChunker@1.0.0 | fa7e2e4723750fd8cb2a85505e4bf86ecae27e044634e59b6dedce1b726f4ac1 | [Indexes > A full implementation]
if (this.objectKeyLength === 1) {
if (this.unique) {
if (this.values.has(key)) throw new Error(`Duplicate key: ${key}`);
this.values.set(key, object);
} else {
if (!this.values.has(key)) this.values.set(key, []);
this.values.get(key).push(object);
}
} else {
if (!this.values.... | unknown | unknown | [Indexes > A full implementation]
if (this.objectKeyLength === 1) {
if (this.unique) {
if (this.values.has(key)) throw new Error(`Duplicate key: ${key}`);
this.values.set(key, object);
} else {
if (!this.values.has(key)) this.values.set(key, []);
this.values.get(key).push(object);
}
} else {
if (!this.values.... | [Indexes > A full implementation]
if (this.objectKeyLength === 1) {
if (this.unique) {
if (this.values.has(key)) throw new Error(`Duplicate key: ${key}`);
this.values.set(key, object);
} else {
if (!this.values.has(key)) this.values.set(key, []);
this.values.get(key).push(object);
}
} else {
if (!this.values.... | code_snippets | ||
5bb0e362-7ee4-4c20-8bea-96e405b477f5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/indexed-object-collections.md | unknown | 337ee459-a922-4558-a083-88a81a53fd6b | 3 | SemanticChunker@1.0.0 | af4740d9d94c50488ce4b097798043b4ffd864cdcc3bf1635fa0d736e7731fe2 | [Indexes > Cardinality]
## Cardinality
Cardinality refers to the **uniqueness of values** in a field/column. In the context of databases, it is a measure of how many distinct values exist in a given field/column. High cardinality means that there are many unique values, while low cardinality means that there are few ... | unknown | unknown | [Indexes > Cardinality]
## Cardinality
Cardinality refers to the **uniqueness of values** in a field/column. In the context of databases, it is a measure of how many distinct values exist in a given field/column. High cardinality means that there are many unique values, while low cardinality means that there are few ... | [Indexes > Cardinality]
## Cardinality
Cardinality refers to the **uniqueness of values** in a field/column. In the context of databases, it is a measure of how many distinct values exist in a given field/column. High cardinality means that there are many unique values, while low cardinality means that there are few ... | code_snippets | ||
6df8434a-735c-4c06-bc5a-73e3b3880d41 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/indexed-object-collections.md | unknown | 337ee459-a922-4558-a083-88a81a53fd6b | 0 | SemanticChunker@1.0.0 | 92f8f762c2e761f5749d214422b76038303e696671b56519783491aef9558556 | ---
title: Exploring indexes and cardinality with JavaScript
shortTitle: Indexes and cardinality
language: javascript
tags: [object]
cover: home-office-2
excerpt: Using indexes can speed up querying object collections significantly, but it seems like a black box for many. Let's dive in!
listed: true
dateModified: 2025-... | unknown | unknown | ---
title: Exploring indexes and cardinality with JavaScript
shortTitle: Indexes and cardinality
language: javascript
tags: [object]
cover: home-office-2
excerpt: Using indexes can speed up querying object collections significantly, but it seems like a black box for many. Let's dive in!
listed: true
dateModified: 2025-... | ---
title: Exploring indexes and cardinality with JavaScript
shortTitle: Indexes and cardinality
language: javascript
tags: [object]
cover: home-office-2
excerpt: Using indexes can speed up querying object collections significantly, but it seems like a black box for many. Let's dive in!
listed: true
dateModified: 2025-... | code_snippets | ||
a111b547-85b8-4eb8-803b-850c1a91a483 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/indexed-object-collections.md | unknown | 337ee459-a922-4558-a083-88a81a53fd6b | 1 | SemanticChunker@1.0.0 | 02aa3ee4a7f488885921de49786aed72704deff9ed6433acda6bfd9745db36fd | [Indexes]
## Indexes
Imagine you have a large **collection of objects** that you need to search through. You can think of this collection as a large **array of objects**, where each object has a **unique identifier** (`id`) and some properties. Naturally, you want to be able to search through this collection quickly ... | unknown | unknown | [Indexes]
## Indexes
Imagine you have a large **collection of objects** that you need to search through. You can think of this collection as a large **array of objects**, where each object has a **unique identifier** (`id`) and some properties. Naturally, you want to be able to search through this collection quickly ... | [Indexes]
## Indexes
Imagine you have a large **collection of objects** that you need to search through. You can think of this collection as a large **array of objects**, where each object has a **unique identifier** (`id`) and some properties. Naturally, you want to be able to search through this collection quickly ... | code_snippets | ||
daa1223d-a5cc-4e89-a226-e2bb2f993866 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/indexed-object-collections.md | unknown | 337ee459-a922-4558-a083-88a81a53fd6b | 10 | SemanticChunker@1.0.0 | e9360a0b351e59871b0a25b2cfc424e8aca5a20e21b74c546d90f075c0d6d2ef | [Indexes > A full implementation]
```
# [continued: part 2]
if (matchedIndexes.length === 0) return null;
console.log(
`Found matching indexes:\n${matchedIndexes.map(i => `- ${i.name} [${i.keys.join(', ')}] (${i.match})`).join('\n')}`
);
// Sort by match type (full match first) and then by number of keys
matc... | unknown | unknown | [Indexes > A full implementation]
```
# [continued: part 2]
if (matchedIndexes.length === 0) return null;
console.log(
`Found matching indexes:\n${matchedIndexes.map(i => `- ${i.name} [${i.keys.join(', ')}] (${i.match})`).join('\n')}`
);
// Sort by match type (full match first) and then by number of keys
matc... | [Indexes > A full implementation]
```
# [continued: part 2]
if (matchedIndexes.length === 0) return null;
console.log(
`Found matching indexes:\n${matchedIndexes.map(i => `- ${i.name} [${i.keys.join(', ')}] (${i.match})`).join('\n')}`
);
// Sort by match type (full match first) and then by number of keys
matc... | code_snippets | ||
e4bbc932-0b87-4007-aec5-8da096144e8d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/indexed-object-collections.md | unknown | 337ee459-a922-4558-a083-88a81a53fd6b | 13 | SemanticChunker@1.0.0 | e38cdf6a8743eea76787348704e5e5d8b5e98192931f90d4337f8bf10c584cce | [Indexes > A full implementation]
```
</code-tabs>
This implementation serves as an **approximation** of how indexes work in real world databases. Querying is done by trying to find the **best matching index** for the given object matcher.
If no index is found, a **full scan** of the objects is performed (5). If an... | unknown | unknown | [Indexes > A full implementation]
```
</code-tabs>
This implementation serves as an **approximation** of how indexes work in real world databases. Querying is done by trying to find the **best matching index** for the given object matcher.
If no index is found, a **full scan** of the objects is performed (5). If an... | [Indexes > A full implementation]
```
</code-tabs>
This implementation serves as an **approximation** of how indexes work in real world databases. Querying is done by trying to find the **best matching index** for the given object matcher.
If no index is found, a **full scan** of the objects is performed (5). If an... | code_snippets | ||
f1a4fc2e-5008-4008-8c46-67848d9d19fd | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/indexed-object-collections.md | unknown | 337ee459-a922-4558-a083-88a81a53fd6b | 9 | SemanticChunker@1.0.0 | 1bf500d5ff339a5afc06d37c5bf0e6de7f8842f1b9a104741774239e8fc22fba | [Indexes > A full implementation]
```
# [continued: part 1]
#findRaw(objectMatcher) {
const objectMatcherKeys = Object.keys(objectMatcher);
const matchingIndex = this.#findMatchingIndex(objectMatcher);
return matchingIndex
? this.#findFromIndex(matchingIndex, objectMatcher, objectMatcherKeys)
: this.#findFromO... | unknown | unknown | [Indexes > A full implementation]
```
# [continued: part 1]
#findRaw(objectMatcher) {
const objectMatcherKeys = Object.keys(objectMatcher);
const matchingIndex = this.#findMatchingIndex(objectMatcher);
return matchingIndex
? this.#findFromIndex(matchingIndex, objectMatcher, objectMatcherKeys)
: this.#findFromO... | [Indexes > A full implementation]
```
# [continued: part 1]
#findRaw(objectMatcher) {
const objectMatcherKeys = Object.keys(objectMatcher);
const matchingIndex = this.#findMatchingIndex(objectMatcher);
return matchingIndex
? this.#findFromIndex(matchingIndex, objectMatcher, objectMatcherKeys)
: this.#findFromO... | code_snippets | ||
f7b8ccaf-33be-4959-856e-f659af4fc0a6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/indexed-object-collections.md | unknown | 337ee459-a922-4558-a083-88a81a53fd6b | 5 | SemanticChunker@1.0.0 | f6cce649fc9aa72a6210c9ef2152d9c42fcf1b129e22a07ef0e3e4821c80a0b5 | [Indexes > Cardinality]
In this example, we create a compound index on the `name` and `id` properties. When we add an object to the collection, we also add it to the compound index. When we want to retrieve an object by its `name` and `id`, we can simply look it up in the compound index. If we want to retrieve the obj... | unknown | unknown | [Indexes > Cardinality]
In this example, we create a compound index on the `name` and `id` properties. When we add an object to the collection, we also add it to the compound index. When we want to retrieve an object by its `name` and `id`, we can simply look it up in the compound index. If we want to retrieve the obj... | [Indexes > Cardinality]
In this example, we create a compound index on the `name` and `id` properties. When we add an object to the collection, we also add it to the compound index. When we want to retrieve an object by its `name` and `id`, we can simply look it up in the compound index. If we want to retrieve the obj... | code_snippets | ||
01ecfdfb-7d80-49ba-97d2-68652c1c0db3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/insert-html-string-before-or-after-element.md | unknown | fb360e07-e728-45bb-a07b-b89e878e2b46 | 1 | SemanticChunker@1.0.0 | 94623b409a9275f2d56e222d41ca884fc5acce3c33e5c1457da6022eddc21c67 | [Insert an HTML string before element]
## Insert an HTML string before element
The **position** that corresponds to inserting an HTML string before the start of a specified element is `'beforebegin'`. You can use `Element.insertAdjacentHTML()` with this position to insert a given HTML string before the start of the s... | unknown | unknown | [Insert an HTML string before element]
## Insert an HTML string before element
The **position** that corresponds to inserting an HTML string before the start of a specified element is `'beforebegin'`. You can use `Element.insertAdjacentHTML()` with this position to insert a given HTML string before the start of the s... | [Insert an HTML string before element]
## Insert an HTML string before element
The **position** that corresponds to inserting an HTML string before the start of a specified element is `'beforebegin'`. You can use `Element.insertAdjacentHTML()` with this position to insert a given HTML string before the start of the s... | code_snippets | ||
310d47c8-5366-4faf-ad25-01844d39379c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/insert-html-string-before-or-after-element.md | unknown | fb360e07-e728-45bb-a07b-b89e878e2b46 | 0 | SemanticChunker@1.0.0 | bcd6165a2c6b3dc78e8008be3b53818d468dac91ef45ac191ae80496df957fb5 | ---
title: Insert HTML string before or after element using JavaScript
shortTitle: Insert HTML string before or after element
language: javascript
tags: [browser]
cover: malibu
excerpt: Learn how to insert an HTML string before or after the start of a specified element using JavaScript.
listed: true
dateModified: 2024-... | unknown | unknown | ---
title: Insert HTML string before or after element using JavaScript
shortTitle: Insert HTML string before or after element
language: javascript
tags: [browser]
cover: malibu
excerpt: Learn how to insert an HTML string before or after the start of a specified element using JavaScript.
listed: true
dateModified: 2024-... | ---
title: Insert HTML string before or after element using JavaScript
shortTitle: Insert HTML string before or after element
language: javascript
tags: [browser]
cover: malibu
excerpt: Learn how to insert an HTML string before or after the start of a specified element using JavaScript.
listed: true
dateModified: 2024-... | code_snippets | ||
49853f85-aba4-4079-a473-e0c866960b19 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/insert-html-string-before-or-after-element.md | unknown | fb360e07-e728-45bb-a07b-b89e878e2b46 | 2 | SemanticChunker@1.0.0 | 235553378d0b24e513cf34777e8865a239b52c82013b9568c7ad8190f5cd31a8 | [Insert an HTML string before element > Insert an HTML string after element]
## Insert an HTML string after element
Similarly, to insert an HTML string after the start of a specified element, you can use `Element.insertAdjacentHTML()` with a **position** of `'afterend'`.
```js
const insertAfter = (el, htmlString) =>... | unknown | unknown | [Insert an HTML string before element > Insert an HTML string after element]
## Insert an HTML string after element
Similarly, to insert an HTML string after the start of a specified element, you can use `Element.insertAdjacentHTML()` with a **position** of `'afterend'`.
```js
const insertAfter = (el, htmlString) =>... | [Insert an HTML string before element > Insert an HTML string after element]
## Insert an HTML string after element
Similarly, to insert an HTML string after the start of a specified element, you can use `Element.insertAdjacentHTML()` with a **position** of `'afterend'`.
```js
const insertAfter = (el, htmlString) =>... | code_snippets | ||
c259f65b-7b59-4ea3-b20a-620ef855d584 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-anagram.md | unknown | df82f0aa-6226-46d6-88fe-4af484f69c40 | 0 | SemanticChunker@1.0.0 | 759f9f5b43fa012a83696bf8404a886ea07d968b814736bf824584ec66c088e4 | ---
title: Check if a JavaScript string is an anagram of another string
shortTitle: String anagram
language: javascript
tags: [string,regexp]
cover: new-york
excerpt: Check if a string is an anagram of another string, handling case-insensitivity and special characters.
listed: true
dateModified: 2024-08-11
---
An anag... | unknown | unknown | ---
title: Check if a JavaScript string is an anagram of another string
shortTitle: String anagram
language: javascript
tags: [string,regexp]
cover: new-york
excerpt: Check if a string is an anagram of another string, handling case-insensitivity and special characters.
listed: true
dateModified: 2024-08-11
---
An anag... | ---
title: Check if a JavaScript string is an anagram of another string
shortTitle: String anagram
language: javascript
tags: [string,regexp]
cover: new-york
excerpt: Check if a string is an anagram of another string, handling case-insensitivity and special characters.
listed: true
dateModified: 2024-08-11
---
An anag... | code_snippets | ||
45839853-6c2c-4c2c-a74c-c92b5534a41b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-node-or-browser.md | unknown | 608ad9bf-4378-43e7-80c3-50164b15f43a | 0 | SemanticChunker@1.0.0 | fe5fb26d6c48c868dea3a0b7cb03377a592863d20d3931cdf744e68189c4c013 | ---
title: Check if the current JavaScript environment is Node.js or a browser
shortTitle: Check if Node.js or browser
language: javascript
tags: [browser,node]
cover: cloudy-rock-formation
excerpt: Determine if the current JavaScript environment is Node.js or a browser.
listed: true
dateModified: 2024-01-10
---
It's ... | unknown | unknown | ---
title: Check if the current JavaScript environment is Node.js or a browser
shortTitle: Check if Node.js or browser
language: javascript
tags: [browser,node]
cover: cloudy-rock-formation
excerpt: Determine if the current JavaScript environment is Node.js or a browser.
listed: true
dateModified: 2024-01-10
---
It's ... | ---
title: Check if the current JavaScript environment is Node.js or a browser
shortTitle: Check if Node.js or browser
language: javascript
tags: [browser,node]
cover: cloudy-rock-formation
excerpt: Determine if the current JavaScript environment is Node.js or a browser.
listed: true
dateModified: 2024-01-10
---
It's ... | code_snippets | ||
58339484-d811-47fd-ac96-b54af1d6059c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-node-or-browser.md | unknown | 608ad9bf-4378-43e7-80c3-50164b15f43a | 2 | SemanticChunker@1.0.0 | 9d77c3bee0e74d22e1e8b8f1dd10043a6dca019f18a497425e4c4e0e982e789d | [Check if the current environment is Node.js > Check if the current environment is a browser]
## Check if the current environment is a browser
Browsers environments, on the other hand, are known to always contain the `window` and `document` global objects. We can use this fact to determine if the current environment ... | unknown | unknown | [Check if the current environment is Node.js > Check if the current environment is a browser]
## Check if the current environment is a browser
Browsers environments, on the other hand, are known to always contain the `window` and `document` global objects. We can use this fact to determine if the current environment ... | [Check if the current environment is Node.js > Check if the current environment is a browser]
## Check if the current environment is a browser
Browsers environments, on the other hand, are known to always contain the `window` and `document` global objects. We can use this fact to determine if the current environment ... | code_snippets | ||
f9467c6f-74a7-4d9a-b07c-0dee6ddaef9b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-node-or-browser.md | unknown | 608ad9bf-4378-43e7-80c3-50164b15f43a | 1 | SemanticChunker@1.0.0 | a77e0476cc0f067a8908e61f5a99129a78ed3eb8f1e2e49e8a48150dfb20bb76 | [Check if the current environment is Node.js]
## Check if the current environment is Node.js
In order to determine if the current environment is Node.js, we can use the `process` global object that provides information about the current Node.js process. We can check if `process`, `process.versions` and `process.versi... | unknown | unknown | [Check if the current environment is Node.js]
## Check if the current environment is Node.js
In order to determine if the current environment is Node.js, we can use the `process` global object that provides information about the current Node.js process. We can check if `process`, `process.versions` and `process.versi... | [Check if the current environment is Node.js]
## Check if the current environment is Node.js
In order to determine if the current environment is Node.js, we can use the `process` global object that provides information about the current Node.js process. We can check if `process`, `process.versions` and `process.versi... | code_snippets | ||
35978632-bf6d-4514-b352-ad66547852b5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-alpha-numeric.md | unknown | dbc80115-a6bf-45c8-8ad2-9549b627e8d3 | 2 | SemanticChunker@1.0.0 | 120fc8bea4f3008a98a10b81ea2029f47943d8f67f481693b17d5bcad37c7885 | [Check if a string contains only alpha characters > Check if a string contains only alphanumeric characters]
## Check if a string contains only alphanumeric characters
Subsequently, you can extend the pattern to include **digits** (`0-9`) by adding them to the range. The resulting pattern will be `[a-zA-Z0-9]`. Addin... | unknown | unknown | [Check if a string contains only alpha characters > Check if a string contains only alphanumeric characters]
## Check if a string contains only alphanumeric characters
Subsequently, you can extend the pattern to include **digits** (`0-9`) by adding them to the range. The resulting pattern will be `[a-zA-Z0-9]`. Addin... | [Check if a string contains only alpha characters > Check if a string contains only alphanumeric characters]
## Check if a string contains only alphanumeric characters
Subsequently, you can extend the pattern to include **digits** (`0-9`) by adding them to the range. The resulting pattern will be `[a-zA-Z0-9]`. Addin... | code_snippets | ||
628bb6be-b2b2-4456-9506-4553360a677b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-alpha-numeric.md | unknown | dbc80115-a6bf-45c8-8ad2-9549b627e8d3 | 0 | SemanticChunker@1.0.0 | 76ffd477cb4d0e2d1becd7600782e23cf378d736aaf8e65fb6ff9f8856e546eb | ---
title: Check if a JavaScript string contains only alpha or alphanumeric characters
shortTitle: String is alpha or alphanumeric
language: javascript
tags: [string,regexp]
cover: mountain-lake-cottage-2
excerpt: Use a regular expression to check if a string contains only alpha or alphanumeric characters in JavaScript... | unknown | unknown | ---
title: Check if a JavaScript string contains only alpha or alphanumeric characters
shortTitle: String is alpha or alphanumeric
language: javascript
tags: [string,regexp]
cover: mountain-lake-cottage-2
excerpt: Use a regular expression to check if a string contains only alpha or alphanumeric characters in JavaScript... | ---
title: Check if a JavaScript string contains only alpha or alphanumeric characters
shortTitle: String is alpha or alphanumeric
language: javascript
tags: [string,regexp]
cover: mountain-lake-cottage-2
excerpt: Use a regular expression to check if a string contains only alpha or alphanumeric characters in JavaScript... | code_snippets | ||
78e6d848-8024-453f-8d47-252debf7065e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-alpha-numeric.md | unknown | dbc80115-a6bf-45c8-8ad2-9549b627e8d3 | 1 | SemanticChunker@1.0.0 | 440d792a250c0dd8cc5cda95f624ebb2ed6cd871ddeac85ca1be719b739f0a29 | [Check if a string contains only alpha characters]
## Check if a string contains only alpha characters
For alpha (alphabetic) characters, you can use a **range** (`[a-zA-Z]`) to match any character from `a` to `z` (lowercase) and `A` to `Z` (uppercase). Simply adding the `*` **quantifier** and the **positional anchor... | unknown | unknown | [Check if a string contains only alpha characters]
## Check if a string contains only alpha characters
For alpha (alphabetic) characters, you can use a **range** (`[a-zA-Z]`) to match any character from `a` to `z` (lowercase) and `A` to `Z` (uppercase). Simply adding the `*` **quantifier** and the **positional anchor... | [Check if a string contains only alpha characters]
## Check if a string contains only alpha characters
For alpha (alphabetic) characters, you can use a **range** (`[a-zA-Z]`) to match any character from `a` to `z` (lowercase) and `A` to `Z` (uppercase). Simply adding the `*` **quantifier** and the **positional anchor... | code_snippets | ||
7ba9a598-ec6b-4b37-ad35-de0309c1f6da | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-absolute-url.md | unknown | 6a3d412b-4119-45b3-8281-9b4fb1676c6e | 0 | SemanticChunker@1.0.0 | 05881bb8adccba2c91e23a877f4e66ac4aa16a1914553c182ee108efd011259b | ---
title: Check if a URL is an absolute URL with JavaScript
shortTitle: Absolute URL check
language: javascript
tags: [string,browser,regexp]
cover: coffee-phone-tray-2
excerpt: Want to know if a string is an absolute URL? This article will help you out.
listed: true
dateModified: 2024-07-09
---
An **absolute URL** i... | unknown | unknown | ---
title: Check if a URL is an absolute URL with JavaScript
shortTitle: Absolute URL check
language: javascript
tags: [string,browser,regexp]
cover: coffee-phone-tray-2
excerpt: Want to know if a string is an absolute URL? This article will help you out.
listed: true
dateModified: 2024-07-09
---
An **absolute URL** i... | ---
title: Check if a URL is an absolute URL with JavaScript
shortTitle: Absolute URL check
language: javascript
tags: [string,browser,regexp]
cover: coffee-phone-tray-2
excerpt: Want to know if a string is an absolute URL? This article will help you out.
listed: true
dateModified: 2024-07-09
---
An **absolute URL** i... | code_snippets | ||
24b9dacc-55a3-499f-bd27-cb56b5697367 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-local-storage-session-storage-enabled.md | unknown | 147d7ff1-e01f-47b9-9209-51526a9dfd80 | 2 | SemanticChunker@1.0.0 | 6ef1b79188af4f9f7922e2a1cb3a011b2c3bae43ae1c3ff561364fbfb4dcfd03 | [Check if `localStorage` is enabled > Check if `sessionStorage` is enabled]
## Check if `sessionStorage` is enabled
Checking if `sessionStorage` is enabled is the exact same as checking if `localStorage` is enabled, except that we will use `sessionStorage` instead of `localStorage`.
```js
const isSessionStorageEnabl... | unknown | unknown | [Check if `localStorage` is enabled > Check if `sessionStorage` is enabled]
## Check if `sessionStorage` is enabled
Checking if `sessionStorage` is enabled is the exact same as checking if `localStorage` is enabled, except that we will use `sessionStorage` instead of `localStorage`.
```js
const isSessionStorageEnabl... | [Check if `localStorage` is enabled > Check if `sessionStorage` is enabled]
## Check if `sessionStorage` is enabled
Checking if `sessionStorage` is enabled is the exact same as checking if `localStorage` is enabled, except that we will use `sessionStorage` instead of `localStorage`.
```js
const isSessionStorageEnabl... | code_snippets | ||
59414f3b-d519-4d65-a16c-219c8309ecb4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-local-storage-session-storage-enabled.md | unknown | 147d7ff1-e01f-47b9-9209-51526a9dfd80 | 0 | SemanticChunker@1.0.0 | 2d96adaebf706593dcc395d2c750cde43d71c1434c5e989b64b7a8e12ba2ca32 | ---
title: Check if localStorage or sessionStorage is enabled
shortTitle: LocalStorage or sessionStorage enabled
language: javascript
tags: [browser]
cover: guitar-living-room
excerpt: Check if `localStorage` or `sessionStorage` is enabled in the browser, using a simple JavaScript function.
listed: true
dateModified: 2... | unknown | unknown | ---
title: Check if localStorage or sessionStorage is enabled
shortTitle: LocalStorage or sessionStorage enabled
language: javascript
tags: [browser]
cover: guitar-living-room
excerpt: Check if `localStorage` or `sessionStorage` is enabled in the browser, using a simple JavaScript function.
listed: true
dateModified: 2... | ---
title: Check if localStorage or sessionStorage is enabled
shortTitle: LocalStorage or sessionStorage enabled
language: javascript
tags: [browser]
cover: guitar-living-room
excerpt: Check if `localStorage` or `sessionStorage` is enabled in the browser, using a simple JavaScript function.
listed: true
dateModified: 2... | code_snippets | ||
a81ad8c7-28db-4f0b-bf96-26e0ed0ee90d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-local-storage-session-storage-enabled.md | unknown | 147d7ff1-e01f-47b9-9209-51526a9dfd80 | 1 | SemanticChunker@1.0.0 | ec1585f9f8d9ce03db9c7464aa3419007fe539cd10d829bf600148d56a265632 | [Check if `localStorage` is enabled]
## Check if `localStorage` is enabled
Checking if `localStorage` is enabled requires some trial and error, quite literally, as we will use a `try...catch` block to test if operations in `localStorage` are supported.
Using `Storage.setItem()` and `Storage.removeItem()` we will **t... | unknown | unknown | [Check if `localStorage` is enabled]
## Check if `localStorage` is enabled
Checking if `localStorage` is enabled requires some trial and error, quite literally, as we will use a `try...catch` block to test if operations in `localStorage` are supported.
Using `Storage.setItem()` and `Storage.removeItem()` we will **t... | [Check if `localStorage` is enabled]
## Check if `localStorage` is enabled
Checking if `localStorage` is enabled requires some trial and error, quite literally, as we will use a `try...catch` block to test if operations in `localStorage` are supported.
Using `Storage.setItem()` and `Storage.removeItem()` we will **t... | code_snippets | ||
6059491e-a023-4bb0-8592-137fd586bc97 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-prime.md | unknown | 6355680c-e296-49cc-a400-c56df36c334f | 0 | SemanticChunker@1.0.0 | c29725efde11bd1a73fc6c7b0e89e4eabd4ae53ff9b0d845ceefd1bffb4763f1 | ---
title: Check if a number is prime in JavaScript
shortTitle: Number is prime
language: javascript
tags: [math,algorithm]
cover: thread
excerpt: Learn how to check if a number is prime and how to generate prime numbers up to a given number in JavaScript.
listed: true
dateModified: 2024-01-25
---
Checking for **prime... | unknown | unknown | ---
title: Check if a number is prime in JavaScript
shortTitle: Number is prime
language: javascript
tags: [math,algorithm]
cover: thread
excerpt: Learn how to check if a number is prime and how to generate prime numbers up to a given number in JavaScript.
listed: true
dateModified: 2024-01-25
---
Checking for **prime... | ---
title: Check if a number is prime in JavaScript
shortTitle: Number is prime
language: javascript
tags: [math,algorithm]
cover: thread
excerpt: Learn how to check if a number is prime and how to generate prime numbers up to a given number in JavaScript.
listed: true
dateModified: 2024-01-25
---
Checking for **prime... | code_snippets | ||
7046f0b2-9052-44a1-8160-f4a3f39b3095 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-prime.md | unknown | 6355680c-e296-49cc-a400-c56df36c334f | 2 | SemanticChunker@1.0.0 | f111493fc48fc6e3bbf4512328e39db6f580f1e496753450c4b3f7698a516214 | [Check if a number is prime > Generate primes up to a given number]
## Generate primes up to a given number
Using the [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) algorithm, we can **generate primes** up to a given number. The algorithm works as follows:
- Generate an array from `2` t... | unknown | unknown | [Check if a number is prime > Generate primes up to a given number]
## Generate primes up to a given number
Using the [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) algorithm, we can **generate primes** up to a given number. The algorithm works as follows:
- Generate an array from `2` t... | [Check if a number is prime > Generate primes up to a given number]
## Generate primes up to a given number
Using the [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) algorithm, we can **generate primes** up to a given number. The algorithm works as follows:
- Generate an array from `2` t... | code_snippets | ||
d9d8b4e9-2453-41c5-84b7-6df8a8f6a91f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-prime.md | unknown | 6355680c-e296-49cc-a400-c56df36c334f | 1 | SemanticChunker@1.0.0 | 04d609e1385aaae9df390e374ea45edb1c4852194598fc1fc4efc97ca8be975d | [Check if a number is prime]
## Check if a number is prime
To check if an integer is a prime number, we can simply use a `for` loop. Inside the loop we can check if the number is **divisible** by any number from `2` to the **square root of the given number**. If such a number is found, we can return `false`. If no su... | unknown | unknown | [Check if a number is prime]
## Check if a number is prime
To check if an integer is a prime number, we can simply use a `for` loop. Inside the loop we can check if the number is **divisible** by any number from `2` to the **square root of the given number**. If such a number is found, we can return `false`. If no su... | [Check if a number is prime]
## Check if a number is prime
To check if an integer is a prime number, we can simply use a `for` loop. Inside the loop we can check if the number is **divisible** by any number from `2` to the **square root of the given number**. If such a number is found, we can return `false`. If no su... | code_snippets | ||
12a2123b-ea39-471d-ae84-99f3585d121e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-leap-year.md | unknown | b4683638-2e66-49ad-a9f2-4a227d06eaa5 | 0 | SemanticChunker@1.0.0 | a04bf1fe5d4ed517c1054af0ca94cdca90942f12c80dabfeb17f9919d389ad31 | ---
title: Check if a year is a leap year in JavaScript
shortTitle: Leap year check
language: javascript
tags: [date]
cover: flowering-hills
excerpt: Having a hard time wrapping your head around the math involved in checking for leap years? You might not need to!
listed: true
dateModified: 2024-05-26
---
A [leap year]... | unknown | unknown | ---
title: Check if a year is a leap year in JavaScript
shortTitle: Leap year check
language: javascript
tags: [date]
cover: flowering-hills
excerpt: Having a hard time wrapping your head around the math involved in checking for leap years? You might not need to!
listed: true
dateModified: 2024-05-26
---
A [leap year]... | ---
title: Check if a year is a leap year in JavaScript
shortTitle: Leap year check
language: javascript
tags: [date]
cover: flowering-hills
excerpt: Having a hard time wrapping your head around the math involved in checking for leap years? You might not need to!
listed: true
dateModified: 2024-05-26
---
A [leap year]... | code_snippets | ||
5c76846c-8918-4561-a592-c7ec73d5c62f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/invert-key-values.md | unknown | af83406e-6dc3-42da-93aa-2f99420d7731 | 1 | SemanticChunker@1.0.0 | e76ec61dedd52c187c4e58831ad564dfc8abf08f1023f2a8585efae118eb09ab | [Invert unique key-value pairs]
## Invert unique key-value pairs
Given that the values of the object are **unique**, you can use `Object.entries()` to get an array of key-value pairs, `Array.prototype.map()` to reverse them, and `Object.fromEntries()` to create a new object from the **inverted pairs**.
```js
const i... | unknown | unknown | [Invert unique key-value pairs]
## Invert unique key-value pairs
Given that the values of the object are **unique**, you can use `Object.entries()` to get an array of key-value pairs, `Array.prototype.map()` to reverse them, and `Object.fromEntries()` to create a new object from the **inverted pairs**.
```js
const i... | [Invert unique key-value pairs]
## Invert unique key-value pairs
Given that the values of the object are **unique**, you can use `Object.entries()` to get an array of key-value pairs, `Array.prototype.map()` to reverse them, and `Object.fromEntries()` to create a new object from the **inverted pairs**.
```js
const i... | code_snippets | ||
80524d6b-d421-4dfc-85ce-cfb7191e5dea | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/invert-key-values.md | unknown | af83406e-6dc3-42da-93aa-2f99420d7731 | 0 | SemanticChunker@1.0.0 | 96194d24445ff3382355b50f69fed652325d8c84d9e014b1826fc180958adf01 | ---
title: Invert the key-value pairs of a JavaScript object
shortTitle: Invert key-values
language: javascript
tags: [object]
cover: pineapple-on-green
excerpt: Learn how to invert the key-value pairs of an object in JavaScript.
listed: true
dateModified: 2024-06-09
---
While fairly uncommon, inverting the key-value ... | unknown | unknown | ---
title: Invert the key-value pairs of a JavaScript object
shortTitle: Invert key-values
language: javascript
tags: [object]
cover: pineapple-on-green
excerpt: Learn how to invert the key-value pairs of an object in JavaScript.
listed: true
dateModified: 2024-06-09
---
While fairly uncommon, inverting the key-value ... | ---
title: Invert the key-value pairs of a JavaScript object
shortTitle: Invert key-values
language: javascript
tags: [object]
cover: pineapple-on-green
excerpt: Learn how to invert the key-value pairs of an object in JavaScript.
listed: true
dateModified: 2024-06-09
---
While fairly uncommon, inverting the key-value ... | code_snippets | ||
ddbf3a29-ac8b-4349-b934-e7e40c4d1c32 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/invert-key-values.md | unknown | af83406e-6dc3-42da-93aa-2f99420d7731 | 2 | SemanticChunker@1.0.0 | 70dd4266994624ef2af0e546430943dd59a9d9becce39263831b75c1727cbbd1 | [Invert unique key-value pairs > Invert key-value pairs with duplicates]
## Invert key-value pairs with duplicates
If the values of the object contain **duplicates**, you'll have to handle them a little differently. Instead of overwriting the keys in the inverted object, you can **append them to an array**. This way,... | unknown | unknown | [Invert unique key-value pairs > Invert key-value pairs with duplicates]
## Invert key-value pairs with duplicates
If the values of the object contain **duplicates**, you'll have to handle them a little differently. Instead of overwriting the keys in the inverted object, you can **append them to an array**. This way,... | [Invert unique key-value pairs > Invert key-value pairs with duplicates]
## Invert key-value pairs with duplicates
If the values of the object contain **duplicates**, you'll have to handle them a little differently. Instead of overwriting the keys in the inverted object, you can **append them to an array**. This way,... | code_snippets | ||
7566c3f9-1426-422f-9c4b-66394efd45eb | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/is-date-valid.md | unknown | 30973289-2118-4e5e-9887-ae3900d3001e | 0 | SemanticChunker@1.0.0 | 1a974c8c0100191677a639e1863098552da8252ce299dab75122045e7407f015 | ---
title: Check if a value is a valid JavaScript date
shortTitle: Check if date is valid
language: javascript
tags: [date]
cover: cave-explorer
excerpt: Learn how you can check if a valid date object can be created from the given values.
listed: true
dateModified: 2024-07-22
---
JavaScript provides a `Date` object th... | unknown | unknown | ---
title: Check if a value is a valid JavaScript date
shortTitle: Check if date is valid
language: javascript
tags: [date]
cover: cave-explorer
excerpt: Learn how you can check if a valid date object can be created from the given values.
listed: true
dateModified: 2024-07-22
---
JavaScript provides a `Date` object th... | ---
title: Check if a value is a valid JavaScript date
shortTitle: Check if date is valid
language: javascript
tags: [date]
cover: cave-explorer
excerpt: Learn how you can check if a valid date object can be created from the given values.
listed: true
dateModified: 2024-07-22
---
JavaScript provides a `Date` object th... | code_snippets | ||
8e36fe93-6ab0-44ef-baf5-36467b6fc175 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/insertion-sort.md | unknown | 7766a823-0a18-40ab-93b9-9c764dba323a | 1 | SemanticChunker@1.0.0 | 8ce31eb8eb700f822553e493995e86efd7edd8366e8ef473a4b9b5ccb507d74d | [Definition]
## Definition
[Insertion sort](https://en.wikipedia.org/wiki/Insertion_sort) is a **simple sorting algorithm** that builds the final sorted array **one element at a time**. It uses **comparison** to find the correct position to insert the current element at, in order to maintain the sorted subarray. | unknown | unknown | [Definition]
## Definition
[Insertion sort](https://en.wikipedia.org/wiki/Insertion_sort) is a **simple sorting algorithm** that builds the final sorted array **one element at a time**. It uses **comparison** to find the correct position to insert the current element at, in order to maintain the sorted subarray. | [Definition]
## Definition
[Insertion sort](https://en.wikipedia.org/wiki/Insertion_sort) is a **simple sorting algorithm** that builds the final sorted array **one element at a time**. It uses **comparison** to find the correct position to insert the current element at, in order to maintain the sorted subarray. | code_snippets | ||
aa78f732-1641-4409-a73b-30bfbf19b914 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/insertion-sort.md | unknown | 7766a823-0a18-40ab-93b9-9c764dba323a | 0 | SemanticChunker@1.0.0 | 86215e8b87e1ed650e910123eca054f8c0152f4f1345d0486fc262b0d268ce3c | ---
title: Insertion sort
language: javascript
tags: [algorithm,array]
cover: white-tablet-2
excerpt: Sort an array of numbers, using the insertion sort algorithm.
listed: true
dateModified: 2023-12-16
--- | unknown | unknown | ---
title: Insertion sort
language: javascript
tags: [algorithm,array]
cover: white-tablet-2
excerpt: Sort an array of numbers, using the insertion sort algorithm.
listed: true
dateModified: 2023-12-16
--- | ---
title: Insertion sort
language: javascript
tags: [algorithm,array]
cover: white-tablet-2
excerpt: Sort an array of numbers, using the insertion sort algorithm.
listed: true
dateModified: 2023-12-16
--- | code_snippets | ||
dd88f7b8-8e3c-43e7-a0cf-0791c281fdc5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/insertion-sort.md | unknown | 7766a823-0a18-40ab-93b9-9c764dba323a | 2 | SemanticChunker@1.0.0 | 32a14ec7a824597c11bd707d6719aab4e9fc2bd400b838f9b64ce7fdbd46bdaa | [Definition > Implementation]
## Implementation
- Use `Array.prototype.reduce()` to iterate over all the elements in the given array.
- If the `length` of the accumulator is `0`, add the current element to it.
- Use `Array.prototype.some()` to iterate over the results in the accumulator until the correct position is ... | unknown | unknown | [Definition > Implementation]
## Implementation
- Use `Array.prototype.reduce()` to iterate over all the elements in the given array.
- If the `length` of the accumulator is `0`, add the current element to it.
- Use `Array.prototype.some()` to iterate over the results in the accumulator until the correct position is ... | [Definition > Implementation]
## Implementation
- Use `Array.prototype.reduce()` to iterate over all the elements in the given array.
- If the `length` of the accumulator is `0`, add the current element to it.
- Use `Array.prototype.some()` to iterate over the results in the accumulator until the correct position is ... | code_snippets | ||
13261b9e-76af-4b6f-bc90-c8224336887f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/json-stringify-pick-keys.md | unknown | e211cf14-471e-4ee6-9ab8-a41bac9b3cd1 | 1 | SemanticChunker@1.0.0 | e79bbafc42f31d1b43202cc025b2758f7bcb38efed6d3dc73c1caf9bfade07f8 | [Array of keys]
## Array of keys
An array of keys allows you to pick specific keys to be included in the stringified version of the object. This is particularly useful when you know the exact shape of the serialized object you want.
```js
const user = {
id: 1234,
username: 'johnsmith',
name: 'John Smith',
age: 3... | unknown | unknown | [Array of keys]
## Array of keys
An array of keys allows you to pick specific keys to be included in the stringified version of the object. This is particularly useful when you know the exact shape of the serialized object you want.
```js
const user = {
id: 1234,
username: 'johnsmith',
name: 'John Smith',
age: 3... | [Array of keys]
## Array of keys
An array of keys allows you to pick specific keys to be included in the stringified version of the object. This is particularly useful when you know the exact shape of the serialized object you want.
```js
const user = {
id: 1234,
username: 'johnsmith',
name: 'John Smith',
age: 3... | code_snippets | ||
3e97a5d6-0632-4425-abb7-bca829b31066 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/json-stringify-pick-keys.md | unknown | e211cf14-471e-4ee6-9ab8-a41bac9b3cd1 | 2 | SemanticChunker@1.0.0 | 23ba55df92de3413ca71f5e38af8b1d9f1f8db8ae0c1ced9374587780738914f | [Array of keys > Replacer function]
## Replacer function
A replacer function is more versatile than an array of keys and takes both the key and value as its arguments. Apart from using it to include or exclude keys, it can also be useful in altering the value of each key in the stringified representation of the objec... | unknown | unknown | [Array of keys > Replacer function]
## Replacer function
A replacer function is more versatile than an array of keys and takes both the key and value as its arguments. Apart from using it to include or exclude keys, it can also be useful in altering the value of each key in the stringified representation of the objec... | [Array of keys > Replacer function]
## Replacer function
A replacer function is more versatile than an array of keys and takes both the key and value as its arguments. Apart from using it to include or exclude keys, it can also be useful in altering the value of each key in the stringified representation of the objec... | code_snippets | ||
fad4d8cd-cd8a-404e-ba30-90d85e2a354e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/json-stringify-pick-keys.md | unknown | e211cf14-471e-4ee6-9ab8-a41bac9b3cd1 | 0 | SemanticChunker@1.0.0 | 21792694ed5eb1ba2b34a187f634aa05f070f6e70588de13b8b38f2882982927 | ---
title: Serialize specific properties from a JSON object
shortTitle: Selective property serialization
language: javascript
tags: [object,json]
cover: coffee-drip
excerpt: Have you ever wanted to serialize an object but only include certain keys? Turns out JavaScript provides an easy way to do this!
listed: true
date... | unknown | unknown | ---
title: Serialize specific properties from a JSON object
shortTitle: Selective property serialization
language: javascript
tags: [object,json]
cover: coffee-drip
excerpt: Have you ever wanted to serialize an object but only include certain keys? Turns out JavaScript provides an easy way to do this!
listed: true
date... | ---
title: Serialize specific properties from a JSON object
shortTitle: Selective property serialization
language: javascript
tags: [object,json]
cover: coffee-drip
excerpt: Have you ever wanted to serialize an object but only include certain keys? Turns out JavaScript provides an easy way to do this!
listed: true
date... | code_snippets | ||
293452d1-d71c-4126-8fe5-44839c25c029 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/iso-format-date-with-timezone.md | unknown | 347d40c7-9495-4392-9c33-a045479748d6 | 0 | SemanticChunker@1.0.0 | f50f5acbc69e98debfbdbd3c2ca256ae59214153a7d3e5afce1dbed94814b253 | ---
title: Format a date to ISO string with timezone using JavaScript
shortTitle: Date to ISO format with timezone
language: javascript
tags: [date]
cover: pop-of-green
excerpt: Convert a date to extended ISO format (ISO 8601), including timezone offset.
listed: true
dateModified: 2024-01-07
---
The [ISO 8601](https:/... | unknown | unknown | ---
title: Format a date to ISO string with timezone using JavaScript
shortTitle: Date to ISO format with timezone
language: javascript
tags: [date]
cover: pop-of-green
excerpt: Convert a date to extended ISO format (ISO 8601), including timezone offset.
listed: true
dateModified: 2024-01-07
---
The [ISO 8601](https:/... | ---
title: Format a date to ISO string with timezone using JavaScript
shortTitle: Date to ISO format with timezone
language: javascript
tags: [date]
cover: pop-of-green
excerpt: Convert a date to extended ISO format (ISO 8601), including timezone offset.
listed: true
dateModified: 2024-01-07
---
The [ISO 8601](https:/... | code_snippets | ||
9c0bfcfe-4235-40c9-93fa-1a9d3e93400f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/iso-format-date-with-timezone.md | unknown | 347d40c7-9495-4392-9c33-a045479748d6 | 3 | SemanticChunker@1.0.0 | 00b30c0d790490a05b3850ef195a6d001dec08334a37dff8a0447a87db5becea | [Format date to ISO string (UTC time) > Check if a string is an ISO formatted date]
## Check if a string is an ISO formatted date
As often as you might need to convert a date to ISO format, you might also need to check if a string is a valid ISO formatted date. Knowing how to convert a date to ISO format, you can sim... | unknown | unknown | [Format date to ISO string (UTC time) > Check if a string is an ISO formatted date]
## Check if a string is an ISO formatted date
As often as you might need to convert a date to ISO format, you might also need to check if a string is a valid ISO formatted date. Knowing how to convert a date to ISO format, you can sim... | [Format date to ISO string (UTC time) > Check if a string is an ISO formatted date]
## Check if a string is an ISO formatted date
As often as you might need to convert a date to ISO format, you might also need to check if a string is a valid ISO formatted date. Knowing how to convert a date to ISO format, you can sim... | code_snippets | ||
d0df33c8-8044-4a19-93a4-6a0dec9abf14 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/iso-format-date-with-timezone.md | unknown | 347d40c7-9495-4392-9c33-a045479748d6 | 2 | SemanticChunker@1.0.0 | 592cd500e6e13cfa866e989da585bf7ff7d5e1e6a107f089d9e8410e5fc9f277 | [Format date to ISO string (UTC time) > Format date to ISO string with timezone offset]
## Format date to ISO string with timezone offset
In order to include the **timezone offset**, you have to build the string yourself.
For this, you'll need to know the timezone offset of the date, which can be retrieved using `Da... | unknown | unknown | [Format date to ISO string (UTC time) > Format date to ISO string with timezone offset]
## Format date to ISO string with timezone offset
In order to include the **timezone offset**, you have to build the string yourself.
For this, you'll need to know the timezone offset of the date, which can be retrieved using `Da... | [Format date to ISO string (UTC time) > Format date to ISO string with timezone offset]
## Format date to ISO string with timezone offset
In order to include the **timezone offset**, you have to build the string yourself.
For this, you'll need to know the timezone offset of the date, which can be retrieved using `Da... | code_snippets | ||
e1df0477-b829-4de0-905c-a90012d98ea4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/iso-format-date-with-timezone.md | unknown | 347d40c7-9495-4392-9c33-a045479748d6 | 1 | SemanticChunker@1.0.0 | 12817aa007e6b17e8f926035389d4f4cd68ae7ab24970bfc4e22e3b13f7b7635 | [Format date to ISO string (UTC time)]
## Format date to ISO string (UTC time)
JavaScript's built-in `Date.prototype.toISOString()` method converts a date to ISO string in **UTC time**.
```js
const toISOString = date => date.toISOString();
toISOString(
new Date('2024-01-06T19:20:34+02:00')
); // '2024-01-06T17:20:... | unknown | unknown | [Format date to ISO string (UTC time)]
## Format date to ISO string (UTC time)
JavaScript's built-in `Date.prototype.toISOString()` method converts a date to ISO string in **UTC time**.
```js
const toISOString = date => date.toISOString();
toISOString(
new Date('2024-01-06T19:20:34+02:00')
); // '2024-01-06T17:20:... | [Format date to ISO string (UTC time)]
## Format date to ISO string (UTC time)
JavaScript's built-in `Date.prototype.toISOString()` method converts a date to ISO string in **UTC time**.
```js
const toISOString = date => date.toISOString();
toISOString(
new Date('2024-01-06T19:20:34+02:00')
); // '2024-01-06T17:20:... | code_snippets | ||
864fe05d-031f-4655-b3b1-4b74906c17d0 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/join-array-into-string.md | unknown | cf8fdc05-fd36-4533-b45f-e092b4dcfe7e | 0 | SemanticChunker@1.0.0 | 3df34d7dee4b84e23e9372ee1e0f4e0628312585ad336c41f7332111c9fc278c | ---
title: Join a JavaScript array into a string, with locale-sensitive separators
shortTitle: Join array into string
language: javascript
tags: [array]
cover: couch-laptop
excerpt: Learn how to leverage `Intl.ListFormat` to join an array into a string, with appropriate separators.
listed: true
dateModified: 2024-01-23... | unknown | unknown | ---
title: Join a JavaScript array into a string, with locale-sensitive separators
shortTitle: Join array into string
language: javascript
tags: [array]
cover: couch-laptop
excerpt: Learn how to leverage `Intl.ListFormat` to join an array into a string, with appropriate separators.
listed: true
dateModified: 2024-01-23... | ---
title: Join a JavaScript array into a string, with locale-sensitive separators
shortTitle: Join array into string
language: javascript
tags: [array]
cover: couch-laptop
excerpt: Learn how to leverage `Intl.ListFormat` to join an array into a string, with appropriate separators.
listed: true
dateModified: 2024-01-23... | code_snippets |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.