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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0e01bace-ff85-4594-8f02-8a8fa8db29c0 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/html/s/keyboard-type-using-inputmode.md | unknown | 913399f9-946b-4f07-bfbd-2b6828d2f4fd | 1 | SemanticChunker@1.0.0 | 2f7a792d99fb469427c3827c834b8a79e21818f8196f20a19dc205d04247f475 | > [!WARNING]
>
> The `inputmode` attribute is not a replacement for the [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-type) attribute. The former acts as a hint to the browser about the type of keyboard to display, while the latter specifies the type of data expected in the input field. | unknown | unknown | > [!WARNING]
>
> The `inputmode` attribute is not a replacement for the [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-type) attribute. The former acts as a hint to the browser about the type of keyboard to display, while the latter specifies the type of data expected in the input field. | > [!WARNING]
>
> The `inputmode` attribute is not a replacement for the [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-type) attribute. The former acts as a hint to the browser about the type of keyboard to display, while the latter specifies the type of data expected in the input field. | code_snippets | ||
7628f587-8738-44a7-ad9f-d27c65800fcc | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/html/s/keyboard-type-using-inputmode.md | unknown | 913399f9-946b-4f07-bfbd-2b6828d2f4fd | 0 | SemanticChunker@1.0.0 | 8ad04a9bbcfe7af15076916c6abdfce2d8d1e00dab8b8107474078c9e2bf9541 | ---
title: Display the right type of keyboard for form inputs
shortTitle: Keyboard type using inputmode
language: html
tags: [form]
cover: yellow-shoes
excerpt: Keyboard input on mobile devices is hard to get right. Here's how to ensure the right keyboard is displayed for each input.
listed: true
dateModified: 2024-12-... | unknown | unknown | ---
title: Display the right type of keyboard for form inputs
shortTitle: Keyboard type using inputmode
language: html
tags: [form]
cover: yellow-shoes
excerpt: Keyboard input on mobile devices is hard to get right. Here's how to ensure the right keyboard is displayed for each input.
listed: true
dateModified: 2024-12-... | ---
title: Display the right type of keyboard for form inputs
shortTitle: Keyboard type using inputmode
language: html
tags: [form]
cover: yellow-shoes
excerpt: Keyboard input on mobile devices is hard to get right. Here's how to ensure the right keyboard is displayed for each input.
listed: true
dateModified: 2024-12-... | code_snippets | ||
d538d5e4-1255-424a-bd32-d55018c131b9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/abort-fetch.md | unknown | f3dc45c3-4c1e-4322-9060-fcbf94bbc358 | 0 | SemanticChunker@1.0.0 | 294895dfc489837295d536c2189670aae8f241cd61a360d3942e4a003020acb6 | ---
title: Abort a fetch request in JavaScript
shortTitle: Abort a fetch request
language: javascript
tags: [function]
cover: cancel-typographer
excerpt: Aborting a fetch request in JavaScript is a common problem. Here's how to handle it correctly.
listed: true
dateModified: 2022-05-15
---
The Fetch API is nowadays th... | unknown | unknown | ---
title: Abort a fetch request in JavaScript
shortTitle: Abort a fetch request
language: javascript
tags: [function]
cover: cancel-typographer
excerpt: Aborting a fetch request in JavaScript is a common problem. Here's how to handle it correctly.
listed: true
dateModified: 2022-05-15
---
The Fetch API is nowadays th... | ---
title: Abort a fetch request in JavaScript
shortTitle: Abort a fetch request
language: javascript
tags: [function]
cover: cancel-typographer
excerpt: Aborting a fetch request in JavaScript is a common problem. Here's how to handle it correctly.
listed: true
dateModified: 2022-05-15
---
The Fetch API is nowadays th... | code_snippets | ||
91e291d1-0e89-485a-9c96-fcb4e418538d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/html/snippet-template.md | unknown | eb68b373-be06-4f52-87b0-280af021c8f1 | 0 | SemanticChunker@1.0.0 | dea9e0a1856f0390c3f3fcf16fe9289dafc473bcf7009d76ef7b8eaa4198cfef | ---
title: My amazing story
shortTitle: Amazing story
language: html
tags: [link]
cover: image
excerpt: A short summary of your story up to 140 characters long.
listed: true
dateModified: 2021-06-13
---
Write your story here. | unknown | unknown | ---
title: My amazing story
shortTitle: Amazing story
language: html
tags: [link]
cover: image
excerpt: A short summary of your story up to 140 characters long.
listed: true
dateModified: 2021-06-13
---
Write your story here. | ---
title: My amazing story
shortTitle: Amazing story
language: html
tags: [link]
cover: image
excerpt: A short summary of your story up to 140 characters long.
listed: true
dateModified: 2021-06-13
---
Write your story here. | code_snippets | ||
45540370-d10c-4995-aab5-7b31b792ea3b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-minutes-hours-days-to-date.md | unknown | 1b9f4d9d-4d88-4530-9889-e574acfa053e | 4 | SemanticChunker@1.0.0 | 66404a3c6481bf9a94de4490b225e73c680e2213f735458951959ff53fd2e4fa | [Add seconds to date > Add days to date]
## Add days to date
For larger values, such as days, we can use `Date.prototype.getDate()` and `Date.prototype.setDate()`, instead.
```js
const addDaysToDate = (date, n) => {
const d = new Date(date);
d.setDate(d.getDate() + n);
return d;
};
addDaysToDate('2020-10-15', 10... | unknown | unknown | [Add seconds to date > Add days to date]
## Add days to date
For larger values, such as days, we can use `Date.prototype.getDate()` and `Date.prototype.setDate()`, instead.
```js
const addDaysToDate = (date, n) => {
const d = new Date(date);
d.setDate(d.getDate() + n);
return d;
};
addDaysToDate('2020-10-15', 10... | [Add seconds to date > Add days to date]
## Add days to date
For larger values, such as days, we can use `Date.prototype.getDate()` and `Date.prototype.setDate()`, instead.
```js
const addDaysToDate = (date, n) => {
const d = new Date(date);
d.setDate(d.getDate() + n);
return d;
};
addDaysToDate('2020-10-15', 10... | code_snippets | ||
73765ea2-2487-4af0-a10e-c6818e757747 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-minutes-hours-days-to-date.md | unknown | 1b9f4d9d-4d88-4530-9889-e574acfa053e | 0 | SemanticChunker@1.0.0 | a35fac6be397805efc8693176169eaea03ed6ac8a5ad277940d8c2282eae9945 | ---
title: How can I add minutes, hours or days to a JavaScript date?
shortTitle: Add minutes, hours or days to date
language: javascript
tags: [date]
cover: orange-coffee-4
excerpt: Learn how to manipulate `Date` objects to add minutes, hours, days and more.
listed: true
dateModified: 2024-01-05
---
You can't get too... | unknown | unknown | ---
title: How can I add minutes, hours or days to a JavaScript date?
shortTitle: Add minutes, hours or days to date
language: javascript
tags: [date]
cover: orange-coffee-4
excerpt: Learn how to manipulate `Date` objects to add minutes, hours, days and more.
listed: true
dateModified: 2024-01-05
---
You can't get too... | ---
title: How can I add minutes, hours or days to a JavaScript date?
shortTitle: Add minutes, hours or days to date
language: javascript
tags: [date]
cover: orange-coffee-4
excerpt: Learn how to manipulate `Date` objects to add minutes, hours, days and more.
listed: true
dateModified: 2024-01-05
---
You can't get too... | code_snippets | ||
73aa9af6-03ef-4d1b-9f99-09bf9952c4b9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-minutes-hours-days-to-date.md | unknown | 1b9f4d9d-4d88-4530-9889-e574acfa053e | 1 | SemanticChunker@1.0.0 | 781873267317dbf1b73c43a50f52825ad3dabea7b94424d21dc07030805f2ec1 | [Add seconds to date]
## Add seconds to date
The `Date` object has `Date.prototype.getTime()` and `Date.prototype.setTime()` built-in. These two methods allow us to **get the current time** in a date object and **set the time** in a date object, respectively.
All values are in **milliseconds**, so we'll have to mult... | unknown | unknown | [Add seconds to date]
## Add seconds to date
The `Date` object has `Date.prototype.getTime()` and `Date.prototype.setTime()` built-in. These two methods allow us to **get the current time** in a date object and **set the time** in a date object, respectively.
All values are in **milliseconds**, so we'll have to mult... | [Add seconds to date]
## Add seconds to date
The `Date` object has `Date.prototype.getTime()` and `Date.prototype.setTime()` built-in. These two methods allow us to **get the current time** in a date object and **set the time** in a date object, respectively.
All values are in **milliseconds**, so we'll have to mult... | code_snippets | ||
7537583b-f176-4c25-b51d-4378b63767a5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-minutes-hours-days-to-date.md | unknown | 1b9f4d9d-4d88-4530-9889-e574acfa053e | 2 | SemanticChunker@1.0.0 | 673dcabd2abafd11055baf19839a1776f914af1921402fd11234d229edc6b91e | [Add seconds to date > Add minutes to date]
## Add minutes to date
Similarly to seconds, we can add minutes to a date by multiplying the number of milliseconds in a minute (`1000 * 60`) before setting the time.
```js
const addMinutesToDate = (date, n) => {
const d = new Date(date);
d.setTime(d.getTime() + n * 60_0... | unknown | unknown | [Add seconds to date > Add minutes to date]
## Add minutes to date
Similarly to seconds, we can add minutes to a date by multiplying the number of milliseconds in a minute (`1000 * 60`) before setting the time.
```js
const addMinutesToDate = (date, n) => {
const d = new Date(date);
d.setTime(d.getTime() + n * 60_0... | [Add seconds to date > Add minutes to date]
## Add minutes to date
Similarly to seconds, we can add minutes to a date by multiplying the number of milliseconds in a minute (`1000 * 60`) before setting the time.
```js
const addMinutesToDate = (date, n) => {
const d = new Date(date);
d.setTime(d.getTime() + n * 60_0... | code_snippets | ||
9220c6d2-20e2-4193-8181-731b443f4e4f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-minutes-hours-days-to-date.md | unknown | 1b9f4d9d-4d88-4530-9889-e574acfa053e | 5 | SemanticChunker@1.0.0 | a88a43ae68b3fef2fd0a21ea5d4d4f5539b5bab0fdd11707b2bf2fea673f6b17 | [Add days to date > Add weekdays to date]
### Add weekdays to date
Weekday calculations are a little more involved. We will use the previous code snippet to add days, as needed.
Before we do so, we will use `Math.sign()` to determine if we should add (`+1`) or subtract (`-1`) days. Then, we will use `Array.from()` t... | unknown | unknown | [Add days to date > Add weekdays to date]
### Add weekdays to date
Weekday calculations are a little more involved. We will use the previous code snippet to add days, as needed.
Before we do so, we will use `Math.sign()` to determine if we should add (`+1`) or subtract (`-1`) days. Then, we will use `Array.from()` t... | [Add days to date > Add weekdays to date]
### Add weekdays to date
Weekday calculations are a little more involved. We will use the previous code snippet to add days, as needed.
Before we do so, we will use `Math.sign()` to determine if we should add (`+1`) or subtract (`-1`) days. Then, we will use `Array.from()` t... | code_snippets | ||
f58889af-e2f4-4da0-aa73-60e0b5e94e2b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-minutes-hours-days-to-date.md | unknown | 1b9f4d9d-4d88-4530-9889-e574acfa053e | 3 | SemanticChunker@1.0.0 | ba71de9438b59898a280086c8c0cab024d23c2b566012056dbcf69b66e825305 | [Add seconds to date > Add hours to date]
## Add hours to date
To add hours to a date, we can multiply the number of milliseconds in an hour (`1000 * 60 * 60`) before setting the time.
```js
const addHoursToDate = (date, n) => {
const d = new Date(date);
d.setTime(d.getTime() + n * 3_600_000);
return d;
};
addHo... | unknown | unknown | [Add seconds to date > Add hours to date]
## Add hours to date
To add hours to a date, we can multiply the number of milliseconds in an hour (`1000 * 60 * 60`) before setting the time.
```js
const addHoursToDate = (date, n) => {
const d = new Date(date);
d.setTime(d.getTime() + n * 3_600_000);
return d;
};
addHo... | [Add seconds to date > Add hours to date]
## Add hours to date
To add hours to a date, we can multiply the number of milliseconds in an hour (`1000 * 60 * 60`) before setting the time.
```js
const addHoursToDate = (date, n) => {
const d = new Date(date);
d.setTime(d.getTime() + n * 3_600_000);
return d;
};
addHo... | code_snippets | ||
096b6c64-3f99-4a56-914c-3b11b00e068a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/6-regexp-tricks.md | unknown | e85aeb70-0691-495e-b9ca-5a379f42b497 | 3 | SemanticChunker@1.0.0 | a4afb1afadde716e27848a17ad26767a3a1d33f9d783f4a623cc5ee413cfb659 | [Capturing groups > Named capturing groups]
## Named capturing groups
Named capturing groups allow you to name a capturing group, by prefixing it with `<name>`:
```js
const str = 'JavaScript is a programming language';
/(?<subject>.+) is a (?<description>.+)/.exec(str);
/*
[
0: 'JavaScript is a programming languag... | unknown | unknown | [Capturing groups > Named capturing groups]
## Named capturing groups
Named capturing groups allow you to name a capturing group, by prefixing it with `<name>`:
```js
const str = 'JavaScript is a programming language';
/(?<subject>.+) is a (?<description>.+)/.exec(str);
/*
[
0: 'JavaScript is a programming languag... | [Capturing groups > Named capturing groups]
## Named capturing groups
Named capturing groups allow you to name a capturing group, by prefixing it with `<name>`:
```js
const str = 'JavaScript is a programming language';
/(?<subject>.+) is a (?<description>.+)/.exec(str);
/*
[
0: 'JavaScript is a programming languag... | code_snippets | ||
1bb06f31-82ab-4c19-9714-765cb5481a05 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/6-regexp-tricks.md | unknown | e85aeb70-0691-495e-b9ca-5a379f42b497 | 6 | SemanticChunker@1.0.0 | c084ae763cfbaa41bb2334850160a60d0485be5178b19e786a97d030c1e11b3c | [Capturing groups > Unicode characters]
## Unicode characters
Finally, you can match unicode characters, using `/p{...}` and the `/u` flag. Examples include, but are not limited to `{Emoji}`, `{Math_Symbols}` and `{Script=Greek}`:
```js
const str = 'Greek looks like this: γεια';
/\p{Script=Greek}+/u.exec(str);
/*
[... | unknown | unknown | [Capturing groups > Unicode characters]
## Unicode characters
Finally, you can match unicode characters, using `/p{...}` and the `/u` flag. Examples include, but are not limited to `{Emoji}`, `{Math_Symbols}` and `{Script=Greek}`:
```js
const str = 'Greek looks like this: γεια';
/\p{Script=Greek}+/u.exec(str);
/*
[... | [Capturing groups > Unicode characters]
## Unicode characters
Finally, you can match unicode characters, using `/p{...}` and the `/u` flag. Examples include, but are not limited to `{Emoji}`, `{Math_Symbols}` and `{Script=Greek}`:
```js
const str = 'Greek looks like this: γεια';
/\p{Script=Greek}+/u.exec(str);
/*
[... | code_snippets | ||
36643bbb-3d09-49cd-8467-f5ab271374a5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/6-regexp-tricks.md | unknown | e85aeb70-0691-495e-b9ca-5a379f42b497 | 1 | SemanticChunker@1.0.0 | 4d737fd8e9e0ef3d1b94d329a56a54e89236c84c614db8063b62f40ab4009d3e | [Capturing groups]
## Capturing groups
Capturing groups allow you to get specific parts of the matched string, simply by wrapping part of the regular expression in parentheses `(...)`:
```js
const str = 'JavaScript is a programming language';
/(JavaScript) is a (.*)/.exec(str);
/*
[
0: 'JavaScript is a programming... | unknown | unknown | [Capturing groups]
## Capturing groups
Capturing groups allow you to get specific parts of the matched string, simply by wrapping part of the regular expression in parentheses `(...)`:
```js
const str = 'JavaScript is a programming language';
/(JavaScript) is a (.*)/.exec(str);
/*
[
0: 'JavaScript is a programming... | [Capturing groups]
## Capturing groups
Capturing groups allow you to get specific parts of the matched string, simply by wrapping part of the regular expression in parentheses `(...)`:
```js
const str = 'JavaScript is a programming language';
/(JavaScript) is a (.*)/.exec(str);
/*
[
0: 'JavaScript is a programming... | code_snippets | ||
48f311b1-8a88-485b-ad21-370f607d4c44 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/6-regexp-tricks.md | unknown | e85aeb70-0691-495e-b9ca-5a379f42b497 | 5 | SemanticChunker@1.0.0 | 04225763919e9428b33b8039a1ef4fea6d216e7c0ddbef0fc6626743af03a585 | [Capturing groups > Lookaheads]
## Lookaheads
Lookaheads allow you to check if something is followed by a certain pattern, without actually matching it. You can create positive lookaheads using `?=` and negative lookaheads using `?!`:
```js
const str = 'JavaScript is not the same as Java and you should remember that... | unknown | unknown | [Capturing groups > Lookaheads]
## Lookaheads
Lookaheads allow you to check if something is followed by a certain pattern, without actually matching it. You can create positive lookaheads using `?=` and negative lookaheads using `?!`:
```js
const str = 'JavaScript is not the same as Java and you should remember that... | [Capturing groups > Lookaheads]
## Lookaheads
Lookaheads allow you to check if something is followed by a certain pattern, without actually matching it. You can create positive lookaheads using `?=` and negative lookaheads using `?!`:
```js
const str = 'JavaScript is not the same as Java and you should remember that... | code_snippets | ||
7443a734-9bf8-4ab3-be2f-1b35f9acd11d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/6-regexp-tricks.md | unknown | e85aeb70-0691-495e-b9ca-5a379f42b497 | 2 | SemanticChunker@1.0.0 | 6e0d5666d20f96e9149d9bfdc68b00c5938b96088f5067e6b550787a527c5f16 | [Capturing groups > Non-capturing groups]
## Non-capturing groups
Non-capturing groups are used for matching something without capturing it, like an either/or matching group that you do not really need. They are defined similarly to capturing groups, but prefixed with `?:`:
```js
const str = 'JavaScript is a program... | unknown | unknown | [Capturing groups > Non-capturing groups]
## Non-capturing groups
Non-capturing groups are used for matching something without capturing it, like an either/or matching group that you do not really need. They are defined similarly to capturing groups, but prefixed with `?:`:
```js
const str = 'JavaScript is a program... | [Capturing groups > Non-capturing groups]
## Non-capturing groups
Non-capturing groups are used for matching something without capturing it, like an either/or matching group that you do not really need. They are defined similarly to capturing groups, but prefixed with `?:`:
```js
const str = 'JavaScript is a program... | code_snippets | ||
78c13f24-d857-4c81-9977-ba26cd3b4ad2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/6-regexp-tricks.md | unknown | e85aeb70-0691-495e-b9ca-5a379f42b497 | 0 | SemanticChunker@1.0.0 | 28c581011184dfb374874468e9075defa5ab8482ded90df7cfcaaff4d9be1f9a | ---
title: 6 JavaScript Regular Expression features you can use today
shortTitle: JavaScript Regular Expression tips
language: javascript
tags: [string,regexp]
cover: taking-photos
excerpt: Learn how to level up your regular expressions game, with features such as backreferences, lookaheads and named groups.
listed: tr... | unknown | unknown | ---
title: 6 JavaScript Regular Expression features you can use today
shortTitle: JavaScript Regular Expression tips
language: javascript
tags: [string,regexp]
cover: taking-photos
excerpt: Learn how to level up your regular expressions game, with features such as backreferences, lookaheads and named groups.
listed: tr... | ---
title: 6 JavaScript Regular Expression features you can use today
shortTitle: JavaScript Regular Expression tips
language: javascript
tags: [string,regexp]
cover: taking-photos
excerpt: Learn how to level up your regular expressions game, with features such as backreferences, lookaheads and named groups.
listed: tr... | code_snippets | ||
fff79233-4bdd-42d2-9acc-2cf7e0b3fc87 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/6-regexp-tricks.md | unknown | e85aeb70-0691-495e-b9ca-5a379f42b497 | 4 | SemanticChunker@1.0.0 | 9e90c8c92f8d20a44a1f790a8fe3daf768f5c4a07dfe73ae2962c9c2266aa822 | [Capturing groups > Capturing group backreferences]
## Capturing group backreferences
Backreferences help you write shorter regular expressions, by repeating an existing capturing group, using `\1`, `\2` etc. Similarly, you can also repeat named capturing groups using `\k<name>`:
```js
const str = 'JavaScript is a p... | unknown | unknown | [Capturing groups > Capturing group backreferences]
## Capturing group backreferences
Backreferences help you write shorter regular expressions, by repeating an existing capturing group, using `\1`, `\2` etc. Similarly, you can also repeat named capturing groups using `\k<name>`:
```js
const str = 'JavaScript is a p... | [Capturing groups > Capturing group backreferences]
## Capturing group backreferences
Backreferences help you write shorter regular expressions, by repeating an existing capturing group, using `\1`, `\2` etc. Similarly, you can also repeat named capturing groups using `\k<name>`:
```js
const str = 'JavaScript is a p... | code_snippets | ||
5ec519b9-8cee-4cc7-a5ba-ffa2a5196cac | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/4-array-methods.md | unknown | d306b79f-2c2b-414a-ad51-9d4aaa311f91 | 0 | SemanticChunker@1.0.0 | b38cacaca60e09714c06dae50aa505fa2ffdcb3e03d5def4832bb9208d4b6e90 | ---
title: 4 JavaScript Array methods you must know
shortTitle: Useful array methods
language: javascript
tags: [array,cheatsheet]
cover: arrays
excerpt: JavaScript arrays have a very robust API offering some amazing tools. Learn the 4 must-know JavaScript array methods in this quick guide.
listed: true
dateModified: 2... | unknown | unknown | ---
title: 4 JavaScript Array methods you must know
shortTitle: Useful array methods
language: javascript
tags: [array,cheatsheet]
cover: arrays
excerpt: JavaScript arrays have a very robust API offering some amazing tools. Learn the 4 must-know JavaScript array methods in this quick guide.
listed: true
dateModified: 2... | ---
title: 4 JavaScript Array methods you must know
shortTitle: Useful array methods
language: javascript
tags: [array,cheatsheet]
cover: arrays
excerpt: JavaScript arrays have a very robust API offering some amazing tools. Learn the 4 must-know JavaScript array methods in this quick guide.
listed: true
dateModified: 2... | code_snippets | ||
7958c51a-bc68-447f-b07b-f95d49020395 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/4-array-methods.md | unknown | d306b79f-2c2b-414a-ad51-9d4aaa311f91 | 2 | SemanticChunker@1.0.0 | e2968474a99a14b2167c83793935f166a734e64d22f3b4a683ec9beff3d56493 | [Array.prototype.map() > Array.prototype.filter()]
## Array.prototype.filter()
[`Array.prototype.filter()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) creates a new array by using a filtering function to keep only elements that return `true` based on that function. ... | unknown | unknown | [Array.prototype.map() > Array.prototype.filter()]
## Array.prototype.filter()
[`Array.prototype.filter()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) creates a new array by using a filtering function to keep only elements that return `true` based on that function. ... | [Array.prototype.map() > Array.prototype.filter()]
## Array.prototype.filter()
[`Array.prototype.filter()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) creates a new array by using a filtering function to keep only elements that return `true` based on that function. ... | code_snippets | ||
9248474e-98cb-43ca-80d7-f940c05f3a78 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/4-array-methods.md | unknown | d306b79f-2c2b-414a-ad51-9d4aaa311f91 | 4 | SemanticChunker@1.0.0 | a4e601c1aea48fcfe8377960d9a323153e0a7bfe529943e2ffb21de5ea620fd9 | [Array.prototype.map() > Array.prototype.find()]
## Array.prototype.find()
[`Array.prototype.find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) returns the first element for which a matcher function returns `true`. The result is a single element from the original arr... | unknown | unknown | [Array.prototype.map() > Array.prototype.find()]
## Array.prototype.find()
[`Array.prototype.find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) returns the first element for which a matcher function returns `true`. The result is a single element from the original arr... | [Array.prototype.map() > Array.prototype.find()]
## Array.prototype.find()
[`Array.prototype.find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) returns the first element for which a matcher function returns `true`. The result is a single element from the original arr... | code_snippets | ||
9e1f1161-356c-47a1-8289-47877e25c177 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/4-array-methods.md | unknown | d306b79f-2c2b-414a-ad51-9d4aaa311f91 | 3 | SemanticChunker@1.0.0 | 6a6abf14bc728e7dcbbf1fb722d0c608fd8e0b8ec30c65b4e9d1dd264a60bb4b | [Array.prototype.map() > Array.prototype.reduce()]
## Array.prototype.reduce()
[`Array.prototype.reduce()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce) creates an output value of any type depending on a reducer function and an initial value. The result can be of any ... | unknown | unknown | [Array.prototype.map() > Array.prototype.reduce()]
## Array.prototype.reduce()
[`Array.prototype.reduce()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce) creates an output value of any type depending on a reducer function and an initial value. The result can be of any ... | [Array.prototype.map() > Array.prototype.reduce()]
## Array.prototype.reduce()
[`Array.prototype.reduce()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce) creates an output value of any type depending on a reducer function and an initial value. The result can be of any ... | code_snippets | ||
d5f0d81f-674f-42a1-aeb4-95d08ba7f062 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/4-array-methods.md | unknown | d306b79f-2c2b-414a-ad51-9d4aaa311f91 | 1 | SemanticChunker@1.0.0 | d99291a8efc0cfa7fc18c8bf6141e55efd95f8190475529c1078c95043ec6118 | [Array.prototype.map()]
## Array.prototype.map()
[`Array.prototype.map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) creates a new array by applying the provided transformation to each element of the original array. The result is an array with the same length as the o... | unknown | unknown | [Array.prototype.map()]
## Array.prototype.map()
[`Array.prototype.map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) creates a new array by applying the provided transformation to each element of the original array. The result is an array with the same length as the o... | [Array.prototype.map()]
## Array.prototype.map()
[`Array.prototype.map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) creates a new array by applying the provided transformation to each element of the original array. The result is an array with the same length as the o... | code_snippets | ||
1a889e97-7769-4aa9-883b-5c1a3461abf8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/html/s/target-blank.md | unknown | b92d2693-9928-430c-b5d7-bd466445ec65 | 0 | SemanticChunker@1.0.0 | 4b99e525b4e9efd0fab3bd56feffe35866da551465dd211a364e6a28e75c7b7c | ---
title: 'Protect your users from malicious websites when using target="_blank"'
shortTitle: 'Safeguarding target="_blank"'
language: html
tags: [link,security]
cover: laptop-with-code
excerpt: Opening a link in a new tab comes with a security vulnerability that you may not be aware of. Protect your users with this s... | unknown | unknown | ---
title: 'Protect your users from malicious websites when using target="_blank"'
shortTitle: 'Safeguarding target="_blank"'
language: html
tags: [link,security]
cover: laptop-with-code
excerpt: Opening a link in a new tab comes with a security vulnerability that you may not be aware of. Protect your users with this s... | ---
title: 'Protect your users from malicious websites when using target="_blank"'
shortTitle: 'Safeguarding target="_blank"'
language: html
tags: [link,security]
cover: laptop-with-code
excerpt: Opening a link in a new tab comes with a security vulnerability that you may not be aware of. Protect your users with this s... | code_snippets | ||
0a1bf762-888b-43cd-a152-754c1cf718d9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/10-vs-code-extensions-for-js-developers.md | unknown | cbd2a37d-674e-4fe1-ba55-7193fd868396 | 8 | SemanticChunker@1.0.0 | 5afb874f697a26bc87d98308a3eed2c1008bdc2315ae926940a72fa8e977fae2 | [ESLint > REST Client]
## REST Client
[REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) allows you to send HTTP requests and view the responses directly in VS Code. This extension supports a wide range of formats and authorization and should work with most setups. | unknown | unknown | [ESLint > REST Client]
## REST Client
[REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) allows you to send HTTP requests and view the responses directly in VS Code. This extension supports a wide range of formats and authorization and should work with most setups. | [ESLint > REST Client]
## REST Client
[REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) allows you to send HTTP requests and view the responses directly in VS Code. This extension supports a wide range of formats and authorization and should work with most setups. | code_snippets | ||
15e6adc2-992c-4634-8282-f3c08b4b7781 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/10-vs-code-extensions-for-js-developers.md | unknown | cbd2a37d-674e-4fe1-ba55-7193fd868396 | 3 | SemanticChunker@1.0.0 | cd924fc9eaa188f76b850eb1b0a83b4677dabeb86bf7fc46b27c48742d30792e | [ESLint > Debugger for Chrome]
## Debugger for Chrome
[Debugger for Chrome](https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome) allows you to debug your JavaScript code in Chrome or Chromium. Breakpoints, call stack inspection and stepping inside a function are only some of its features. | unknown | unknown | [ESLint > Debugger for Chrome]
## Debugger for Chrome
[Debugger for Chrome](https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome) allows you to debug your JavaScript code in Chrome or Chromium. Breakpoints, call stack inspection and stepping inside a function are only some of its features. | [ESLint > Debugger for Chrome]
## Debugger for Chrome
[Debugger for Chrome](https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome) allows you to debug your JavaScript code in Chrome or Chromium. Breakpoints, call stack inspection and stepping inside a function are only some of its features. | code_snippets | ||
1921761d-b544-459a-8a58-c91762d13a78 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/10-vs-code-extensions-for-js-developers.md | unknown | cbd2a37d-674e-4fe1-ba55-7193fd868396 | 10 | SemanticChunker@1.0.0 | c685b9f7a42c18cc56edd460b8ab1407ad5ef11dbc2d32e4cb7e2f358642d315 | [ESLint > Fira Code]
## Fira Code
[Fira Code](https://github.com/tonsky/FiraCode) is not a traditional VS Code extension and might take a couple more steps to set up, but it's a superb programming font with ligatures that will help you scan code faster once you get used to it. | unknown | unknown | [ESLint > Fira Code]
## Fira Code
[Fira Code](https://github.com/tonsky/FiraCode) is not a traditional VS Code extension and might take a couple more steps to set up, but it's a superb programming font with ligatures that will help you scan code faster once you get used to it. | [ESLint > Fira Code]
## Fira Code
[Fira Code](https://github.com/tonsky/FiraCode) is not a traditional VS Code extension and might take a couple more steps to set up, but it's a superb programming font with ligatures that will help you scan code faster once you get used to it. | code_snippets | ||
351f95f1-9c69-42b0-b232-39b5ddb3d29b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/10-vs-code-extensions-for-js-developers.md | unknown | cbd2a37d-674e-4fe1-ba55-7193fd868396 | 9 | SemanticChunker@1.0.0 | 02c3aa33ef35df23185974778de3bf5a6cabbac4c6e47faa264d8e1f953369c6 | [ESLint > One Dark Pro]
## One Dark Pro
[One Dark Pro](https://marketplace.visualstudio.com/items?itemName=zhuangtongfa.Material-theme) is one of the most popular VS Code themes and with very good reason. It provides a clean theme with a nice palette that has great contrast and is very comfortable to use on a daily b... | unknown | unknown | [ESLint > One Dark Pro]
## One Dark Pro
[One Dark Pro](https://marketplace.visualstudio.com/items?itemName=zhuangtongfa.Material-theme) is one of the most popular VS Code themes and with very good reason. It provides a clean theme with a nice palette that has great contrast and is very comfortable to use on a daily b... | [ESLint > One Dark Pro]
## One Dark Pro
[One Dark Pro](https://marketplace.visualstudio.com/items?itemName=zhuangtongfa.Material-theme) is one of the most popular VS Code themes and with very good reason. It provides a clean theme with a nice palette that has great contrast and is very comfortable to use on a daily b... | code_snippets | ||
38e91420-9954-4442-980f-d18587dedf15 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/10-vs-code-extensions-for-js-developers.md | unknown | cbd2a37d-674e-4fe1-ba55-7193fd868396 | 7 | SemanticChunker@1.0.0 | 0991bc3efde86fd4e3324e43886884c2a9f0331dcf9241297c0054a4c781c90e | [ESLint > Live Server]
## Live Server
[Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) gives you an easy way to serve web pages from VS Code, making previewing and debugging a lot easier. One of the core features is the live reload support that many developers are used to. | unknown | unknown | [ESLint > Live Server]
## Live Server
[Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) gives you an easy way to serve web pages from VS Code, making previewing and debugging a lot easier. One of the core features is the live reload support that many developers are used to. | [ESLint > Live Server]
## Live Server
[Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) gives you an easy way to serve web pages from VS Code, making previewing and debugging a lot easier. One of the core features is the live reload support that many developers are used to. | code_snippets | ||
4782f122-81f7-423f-9763-bf08d0d2197e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/10-vs-code-extensions-for-js-developers.md | unknown | cbd2a37d-674e-4fe1-ba55-7193fd868396 | 6 | SemanticChunker@1.0.0 | 23d9397c776e953392ac4ded589054beca82a4c2ec6be252f5d45117715736bf | [ESLint > TODO Highlight]
## TODO Highlight
[TODO Highlight](https://marketplace.visualstudio.com/items?itemName=wayou.vscode-todo-highlight) simplifies tracking leftover tasks by allowing you to list all of your TODO annotations, as well as adding a handy background highlight to them to make them pop out immediately... | unknown | unknown | [ESLint > TODO Highlight]
## TODO Highlight
[TODO Highlight](https://marketplace.visualstudio.com/items?itemName=wayou.vscode-todo-highlight) simplifies tracking leftover tasks by allowing you to list all of your TODO annotations, as well as adding a handy background highlight to them to make them pop out immediately... | [ESLint > TODO Highlight]
## TODO Highlight
[TODO Highlight](https://marketplace.visualstudio.com/items?itemName=wayou.vscode-todo-highlight) simplifies tracking leftover tasks by allowing you to list all of your TODO annotations, as well as adding a handy background highlight to them to make them pop out immediately... | code_snippets | ||
6716ea64-6f6d-4b4c-8a8f-0915c6951e5d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/10-vs-code-extensions-for-js-developers.md | unknown | cbd2a37d-674e-4fe1-ba55-7193fd868396 | 4 | SemanticChunker@1.0.0 | c1426359ba152fa06744821da7338d0b87288f70065e3a02b3b294f6c7de2d82 | [ESLint > Bracket Pair Colorizer 2]
## Bracket Pair Colorizer 2
[Bracket Pair Colorizer 2](https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer-2) makes reading code faster as it makes matching brackets the same color. This extension for VS Code improves upon its predecessor by providi... | unknown | unknown | [ESLint > Bracket Pair Colorizer 2]
## Bracket Pair Colorizer 2
[Bracket Pair Colorizer 2](https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer-2) makes reading code faster as it makes matching brackets the same color. This extension for VS Code improves upon its predecessor by providi... | [ESLint > Bracket Pair Colorizer 2]
## Bracket Pair Colorizer 2
[Bracket Pair Colorizer 2](https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer-2) makes reading code faster as it makes matching brackets the same color. This extension for VS Code improves upon its predecessor by providi... | code_snippets | ||
78e00226-a556-48ff-9e0e-339b0aa75638 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/10-vs-code-extensions-for-js-developers.md | unknown | cbd2a37d-674e-4fe1-ba55-7193fd868396 | 0 | SemanticChunker@1.0.0 | 5919ce53009baddb816e621dbc2a0447ff1ef4d2c60669731ab8a8c7a9020020 | ---
title: 10 must-have VS Code extensions for JavaScript developers
shortTitle: Essential VS Code extensions
language: javascript
tags: [devtools,vscode]
cover: computer-screens
excerpt: Boost your productivity with these 10 essential VS Code extensions for JavaScript developers.
listed: false
dateModified: 2021-06-12... | unknown | unknown | ---
title: 10 must-have VS Code extensions for JavaScript developers
shortTitle: Essential VS Code extensions
language: javascript
tags: [devtools,vscode]
cover: computer-screens
excerpt: Boost your productivity with these 10 essential VS Code extensions for JavaScript developers.
listed: false
dateModified: 2021-06-12... | ---
title: 10 must-have VS Code extensions for JavaScript developers
shortTitle: Essential VS Code extensions
language: javascript
tags: [devtools,vscode]
cover: computer-screens
excerpt: Boost your productivity with these 10 essential VS Code extensions for JavaScript developers.
listed: false
dateModified: 2021-06-12... | code_snippets | ||
8830abb8-86d9-47ee-a24e-115c4584eb60 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/10-vs-code-extensions-for-js-developers.md | unknown | cbd2a37d-674e-4fe1-ba55-7193fd868396 | 2 | SemanticChunker@1.0.0 | 17cccc409cd293236e52ae1bff1f3989c5917abea70afcecabd20209a4524e09 | [ESLint > GitLens]
## GitLens
[GitLens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens) is a very powerful collaboration tool for VS Code. It provides many useful tools for git such as blame, code authorship, activity heatmaps, recent changes, file history and even commit search. | unknown | unknown | [ESLint > GitLens]
## GitLens
[GitLens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens) is a very powerful collaboration tool for VS Code. It provides many useful tools for git such as blame, code authorship, activity heatmaps, recent changes, file history and even commit search. | [ESLint > GitLens]
## GitLens
[GitLens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens) is a very powerful collaboration tool for VS Code. It provides many useful tools for git such as blame, code authorship, activity heatmaps, recent changes, file history and even commit search. | code_snippets | ||
91d30682-3d2b-46bc-8456-c2d171462cfc | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/10-vs-code-extensions-for-js-developers.md | unknown | cbd2a37d-674e-4fe1-ba55-7193fd868396 | 1 | SemanticChunker@1.0.0 | 5986f8dae5c935727204ecfb5920f1e58b3e8e1f143fcf3cf4b0d0205cb52e5d | [ESLint]
## ESLint
[ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) turns the popular JavaScript linter into an extension of VS Code. It automatically reads your linting configuration, identifies problems and even fixes them for you, if you want. | unknown | unknown | [ESLint]
## ESLint
[ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) turns the popular JavaScript linter into an extension of VS Code. It automatically reads your linting configuration, identifies problems and even fixes them for you, if you want. | [ESLint]
## ESLint
[ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) turns the popular JavaScript linter into an extension of VS Code. It automatically reads your linting configuration, identifies problems and even fixes them for you, if you want. | code_snippets | ||
a2fad243-6f9a-42b3-aae0-cba936e1a626 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/10-vs-code-extensions-for-js-developers.md | unknown | cbd2a37d-674e-4fe1-ba55-7193fd868396 | 5 | SemanticChunker@1.0.0 | 2d574542f01101ad94bb528c0b1a523ad21ec74f29c857ad78434ad9a6b3dc6b | [ESLint > Bookmarks]
## Bookmarks
[Bookmarks](https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks) is one of those extensions that will significantly reduce your time jumping between different files, as it allows you to save important positions and navigate back to them easily and quickly. | unknown | unknown | [ESLint > Bookmarks]
## Bookmarks
[Bookmarks](https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks) is one of those extensions that will significantly reduce your time jumping between different files, as it allows you to save important positions and navigate back to them easily and quickly. | [ESLint > Bookmarks]
## Bookmarks
[Bookmarks](https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks) is one of those extensions that will significantly reduce your time jumping between different files, as it allows you to save important positions and navigate back to them easily and quickly. | code_snippets | ||
ba735e2d-f64a-468f-a3ed-1460a4f4727e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/html/s/start-ordered-list-at-different-number.md | unknown | 4a3f8d58-e124-4e4e-be3a-737f4d6cb59e | 0 | SemanticChunker@1.0.0 | 95236d6ed172998d68bc37c016f22866893c7939e6043fa72dfbe8784292d660 | ---
title: Start your ordered HTML lists at a different number
shortTitle: Ordered lists starting number
language: html
tags: [content]
cover: neon-desk-1
excerpt: Did you know you can customize the starting number of your ordered lists? Learn how with this quick tip.
listed: true
dateModified: 2024-05-10
---
Ordered ... | unknown | unknown | ---
title: Start your ordered HTML lists at a different number
shortTitle: Ordered lists starting number
language: html
tags: [content]
cover: neon-desk-1
excerpt: Did you know you can customize the starting number of your ordered lists? Learn how with this quick tip.
listed: true
dateModified: 2024-05-10
---
Ordered ... | ---
title: Start your ordered HTML lists at a different number
shortTitle: Ordered lists starting number
language: html
tags: [content]
cover: neon-desk-1
excerpt: Did you know you can customize the starting number of your ordered lists? Learn how with this quick tip.
listed: true
dateModified: 2024-05-10
---
Ordered ... | code_snippets | ||
4ba6de0a-7d36-4366-8ce9-665fad3eea09 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-key-value-pair-to-object.md | unknown | 148b1fcd-5126-43ab-8675-88fba4795e11 | 3 | SemanticChunker@1.0.0 | c799a7c931bfd5cd076b0ee0283c4414551b2c699a0bf23002bc0d18f7145601 | [Dot notation > Object.assign()]
## Object.assign()
`Object.assign()` is slightly different than the previous two options. It can be used to add multiple properties to an object at once and it can also **shallow merge** two or more objects. It is not as performant, however, so it should only be used when necessary.
... | unknown | unknown | [Dot notation > Object.assign()]
## Object.assign()
`Object.assign()` is slightly different than the previous two options. It can be used to add multiple properties to an object at once and it can also **shallow merge** two or more objects. It is not as performant, however, so it should only be used when necessary.
... | [Dot notation > Object.assign()]
## Object.assign()
`Object.assign()` is slightly different than the previous two options. It can be used to add multiple properties to an object at once and it can also **shallow merge** two or more objects. It is not as performant, however, so it should only be used when necessary.
... | code_snippets | ||
5a910cfb-af87-4b9f-bca1-4ec3ece90ecb | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-key-value-pair-to-object.md | unknown | 148b1fcd-5126-43ab-8675-88fba4795e11 | 2 | SemanticChunker@1.0.0 | 436771180f636f8b9cd73453a371008cce51e4b259be946439e9176f9968aac3 | [Dot notation > Square bracket notation]
## Square bracket notation
Similar to dot notation, square bracket notation comes in handy when dealing with **dynamic keys**, but can also work with static keys. Apart from that, it's exactly the same as dot notation both in functionality and performance.
```js
const obj = {... | unknown | unknown | [Dot notation > Square bracket notation]
## Square bracket notation
Similar to dot notation, square bracket notation comes in handy when dealing with **dynamic keys**, but can also work with static keys. Apart from that, it's exactly the same as dot notation both in functionality and performance.
```js
const obj = {... | [Dot notation > Square bracket notation]
## Square bracket notation
Similar to dot notation, square bracket notation comes in handy when dealing with **dynamic keys**, but can also work with static keys. Apart from that, it's exactly the same as dot notation both in functionality and performance.
```js
const obj = {... | code_snippets | ||
8513a0ef-da78-429c-add0-4fec8d8eb9d2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-key-value-pair-to-object.md | unknown | 148b1fcd-5126-43ab-8675-88fba4795e11 | 4 | SemanticChunker@1.0.0 | 145d962676f4fcbeffa941a025a73388bf6f219f19798dc727d62cff368fd9df | [Dot notation > Object.defineProperty()]
## Object.defineProperty()
Another, less-common, way to add a key-value pair to an object is to use `Object.defineProperty()`. This is the lest performant way to add a key-value pair to an object, but it allows the new property to be **precisely defined**. This function accept... | unknown | unknown | [Dot notation > Object.defineProperty()]
## Object.defineProperty()
Another, less-common, way to add a key-value pair to an object is to use `Object.defineProperty()`. This is the lest performant way to add a key-value pair to an object, but it allows the new property to be **precisely defined**. This function accept... | [Dot notation > Object.defineProperty()]
## Object.defineProperty()
Another, less-common, way to add a key-value pair to an object is to use `Object.defineProperty()`. This is the lest performant way to add a key-value pair to an object, but it allows the new property to be **precisely defined**. This function accept... | code_snippets | ||
c44a44c2-1870-43a4-a46d-0872197b15f3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-key-value-pair-to-object.md | unknown | 148b1fcd-5126-43ab-8675-88fba4795e11 | 0 | SemanticChunker@1.0.0 | f1a0fc413a697b325bc56d84f151287777555a1fcf58d65f8112f5dd83fdb3c2 | ---
title: How can I add a key-value pair to a JavaScript object?
shortTitle: Add key-value pair to object
language: javascript
tags: [object]
cover: pineapple-laptop
excerpt: Adding a key-value pair to a JavaScript object is straightforward, yet there are multiple ways available to do so.
listed: true
dateModified: 20... | unknown | unknown | ---
title: How can I add a key-value pair to a JavaScript object?
shortTitle: Add key-value pair to object
language: javascript
tags: [object]
cover: pineapple-laptop
excerpt: Adding a key-value pair to a JavaScript object is straightforward, yet there are multiple ways available to do so.
listed: true
dateModified: 20... | ---
title: How can I add a key-value pair to a JavaScript object?
shortTitle: Add key-value pair to object
language: javascript
tags: [object]
cover: pineapple-laptop
excerpt: Adding a key-value pair to a JavaScript object is straightforward, yet there are multiple ways available to do so.
listed: true
dateModified: 20... | code_snippets | ||
e64edf32-4d38-4748-88f1-a3f37fa126cb | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-key-value-pair-to-object.md | unknown | 148b1fcd-5126-43ab-8675-88fba4795e11 | 1 | SemanticChunker@1.0.0 | ebb03630eee3f830c7f6af6482837b8a82bde9ecd54d13908580c332564d5e23 | [Dot notation]
## Dot notation
The most common and straightforward way to add a key-value pair to an object is to use the dot notation. You have probably already used this in the past, and it's sufficient in most situations you will encounter.
```js
const obj = { a: 1 };
obj.b = 2;
obj.c = 3;
// obj = { a: 1, b: 2, ... | unknown | unknown | [Dot notation]
## Dot notation
The most common and straightforward way to add a key-value pair to an object is to use the dot notation. You have probably already used this in the past, and it's sufficient in most situations you will encounter.
```js
const obj = { a: 1 };
obj.b = 2;
obj.c = 3;
// obj = { a: 1, b: 2, ... | [Dot notation]
## Dot notation
The most common and straightforward way to add a key-value pair to an object is to use the dot notation. You have probably already used this in the past, and it's sufficient in most situations you will encounter.
```js
const obj = { a: 1 };
obj.b = 2;
obj.c = 3;
// obj = { a: 1, b: 2, ... | code_snippets | ||
f2cb0f7a-d3d9-408e-a30a-44aca4fc5721 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-key-value-pair-to-object.md | unknown | 148b1fcd-5126-43ab-8675-88fba4795e11 | 5 | SemanticChunker@1.0.0 | f60f3c64abe6ba462be2683255a8c4f26f738b04d5663b4edcf981dce2446a76 | [Dot notation > Object spread operator]
## Object spread operator
Last but not least, there's the object spread operator (`...`). Contrary to previous methods, this one **doesn't mutate the original object**, but instead returns a new object with the added properties. As expected, the performance of this approach is ... | unknown | unknown | [Dot notation > Object spread operator]
## Object spread operator
Last but not least, there's the object spread operator (`...`). Contrary to previous methods, this one **doesn't mutate the original object**, but instead returns a new object with the added properties. As expected, the performance of this approach is ... | [Dot notation > Object spread operator]
## Object spread operator
Last but not least, there's the object spread operator (`...`). Contrary to previous methods, this one **doesn't mutate the original object**, but instead returns a new object with the added properties. As expected, the performance of this approach is ... | code_snippets | ||
ae6153bc-6d0f-42b1-9b00-7d9ad7662a30 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/html/s/zooming-accessibility-tips.md | unknown | 19d22512-4efe-4747-b8a5-2068fec6f919 | 0 | SemanticChunker@1.0.0 | 568730867174a11c9911a210ce895f5279368122531f55b100bd4127fb4db4e6 | ---
title: Why using maximum-scale can harm your page's accessibility
shortTitle: Accessibility and maximum-scale
language: html
tags: [accessibility,metadata,head]
cover: camera-zoom
excerpt: Using the viewport meta tag incorrectly can harm your website's accessibility. Learn how to prevent problems with this handy gu... | unknown | unknown | ---
title: Why using maximum-scale can harm your page's accessibility
shortTitle: Accessibility and maximum-scale
language: html
tags: [accessibility,metadata,head]
cover: camera-zoom
excerpt: Using the viewport meta tag incorrectly can harm your website's accessibility. Learn how to prevent problems with this handy gu... | ---
title: Why using maximum-scale can harm your page's accessibility
shortTitle: Accessibility and maximum-scale
language: html
tags: [accessibility,metadata,head]
cover: camera-zoom
excerpt: Using the viewport meta tag incorrectly can harm your website's accessibility. Learn how to prevent problems with this handy gu... | code_snippets | ||
5ef53bcd-480e-45dc-8a02-49f7cb01242c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-filtering-tips.md | unknown | dd57006d-14a3-447e-ba32-f91ca6e44ee8 | 1 | SemanticChunker@1.0.0 | 9e5a56efb4ce6f343768c587eddf0eee488b7dc15a40e6cdb8e03069396d04df | [Find a single value]
## Find a single value
If you are looking for a single result in an array, you can use `Array.prototype.find()` instead. This will return the first element that satisfies the condition, or `undefined` if no such element exists. It's much faster than `Array.prototype.filter()`, as it will stop it... | unknown | unknown | [Find a single value]
## Find a single value
If you are looking for a single result in an array, you can use `Array.prototype.find()` instead. This will return the first element that satisfies the condition, or `undefined` if no such element exists. It's much faster than `Array.prototype.filter()`, as it will stop it... | [Find a single value]
## Find a single value
If you are looking for a single result in an array, you can use `Array.prototype.find()` instead. This will return the first element that satisfies the condition, or `undefined` if no such element exists. It's much faster than `Array.prototype.filter()`, as it will stop it... | code_snippets | ||
92dd4806-9f2b-4458-b42a-1e8d61288a84 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-filtering-tips.md | unknown | dd57006d-14a3-447e-ba32-f91ca6e44ee8 | 2 | SemanticChunker@1.0.0 | f01fc5b01d8a100c0a9bcf4572a6cc6a84a7dcd9def58d57589b282e2b189284 | [Find a single value > Remove a single value]
## Remove a single value
Similarly, if you want to remove a single value from an array, you can use `Array.prototype.findIndex()` to find the index of the element you want to remove. Then, use `Array.prototype.slice()` to remove it. While this is a little more verbose and... | unknown | unknown | [Find a single value > Remove a single value]
## Remove a single value
Similarly, if you want to remove a single value from an array, you can use `Array.prototype.findIndex()` to find the index of the element you want to remove. Then, use `Array.prototype.slice()` to remove it. While this is a little more verbose and... | [Find a single value > Remove a single value]
## Remove a single value
Similarly, if you want to remove a single value from an array, you can use `Array.prototype.findIndex()` to find the index of the element you want to remove. Then, use `Array.prototype.slice()` to remove it. While this is a little more verbose and... | code_snippets | ||
ade86bd1-fb8c-475d-8cd6-f87674c1e20e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-filtering-tips.md | unknown | dd57006d-14a3-447e-ba32-f91ca6e44ee8 | 0 | SemanticChunker@1.0.0 | 6302df1564f67a45e69f38e035df6a87357660ca7787a9ac8b88f7579164fc82 | ---
title: JavaScript array filtering tips
shortTitle: Array filtering tips
language: javascript
tags: [array]
cover: rocky-beach-waves
excerpt: A few tips and tricks to help you filter arrays in JavaScript more efficiently.
listed: true
dateModified: 2022-09-28
---
While `Array.prototype.filter()` is a very convenien... | unknown | unknown | ---
title: JavaScript array filtering tips
shortTitle: Array filtering tips
language: javascript
tags: [array]
cover: rocky-beach-waves
excerpt: A few tips and tricks to help you filter arrays in JavaScript more efficiently.
listed: true
dateModified: 2022-09-28
---
While `Array.prototype.filter()` is a very convenien... | ---
title: JavaScript array filtering tips
shortTitle: Array filtering tips
language: javascript
tags: [array]
cover: rocky-beach-waves
excerpt: A few tips and tricks to help you filter arrays in JavaScript more efficiently.
listed: true
dateModified: 2022-09-28
---
While `Array.prototype.filter()` is a very convenien... | code_snippets | ||
bbbf17ec-3250-42b8-bd4c-8c2b96a97153 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-filtering-tips.md | unknown | dd57006d-14a3-447e-ba32-f91ca6e44ee8 | 3 | SemanticChunker@1.0.0 | 757b184e880d81b0e884e8261bff3714642d8057b14fa237bcaa26ff92a1e8c8 | [Find a single value > Additional notes]
## Additional notes
In many cases, such changes will not make a drastic difference in your application's performance. It never hurts, however, to be aware of all the options and use the best one for your specific use case. Changes such as these will make more sense when workin... | unknown | unknown | [Find a single value > Additional notes]
## Additional notes
In many cases, such changes will not make a drastic difference in your application's performance. It never hurts, however, to be aware of all the options and use the best one for your specific use case. Changes such as these will make more sense when workin... | [Find a single value > Additional notes]
## Additional notes
In many cases, such changes will not make a drastic difference in your application's performance. It never hurts, however, to be aware of all the options and use the best one for your specific use case. Changes such as these will make more sense when workin... | code_snippets | ||
663c73ff-3ad3-40a7-8b81-0f4a9b08df0a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-has-only-one-match-or-many.md | unknown | 2b77b3fa-7554-4a14-8149-48a7b489701b | 3 | SemanticChunker@1.0.0 | b55c28ca7f39cfd35ebbb14346f0f95dad8879d3dd56ed78ca9f5ccc6f413ffa | [Check if an array has only one match > Check if an array has many matches]
## Check if an array has many matches
In order to check if an array has more than one value matching the given function, you can use the same approach. The only difference is that you need to change the comparison operator from `===` to `>`.
... | unknown | unknown | [Check if an array has only one match > Check if an array has many matches]
## Check if an array has many matches
In order to check if an array has more than one value matching the given function, you can use the same approach. The only difference is that you need to change the comparison operator from `===` to `>`.
... | [Check if an array has only one match > Check if an array has many matches]
## Check if an array has many matches
In order to check if an array has more than one value matching the given function, you can use the same approach. The only difference is that you need to change the comparison operator from `===` to `>`.
... | code_snippets | ||
a63e5811-f692-41d8-9298-aa56e44a9c7f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-has-only-one-match-or-many.md | unknown | 2b77b3fa-7554-4a14-8149-48a7b489701b | 2 | SemanticChunker@1.0.0 | 71cfe46953e22af22eebf52bd4d20ba04997aeb9fc4bb47a881ed66f13e55f56 | [Check if an array has only one match > Find the index of the only matching element]
## Find the index of the only matching element
To find the index of the only matching element, you can use `Array.prototype.findIndex()`.
```js
const findIndex = (arr, fn) => arr.findIndex(fn);
findIndex([1, 2, 3, 4], x => x % 2); ... | unknown | unknown | [Check if an array has only one match > Find the index of the only matching element]
## Find the index of the only matching element
To find the index of the only matching element, you can use `Array.prototype.findIndex()`.
```js
const findIndex = (arr, fn) => arr.findIndex(fn);
findIndex([1, 2, 3, 4], x => x % 2); ... | [Check if an array has only one match > Find the index of the only matching element]
## Find the index of the only matching element
To find the index of the only matching element, you can use `Array.prototype.findIndex()`.
```js
const findIndex = (arr, fn) => arr.findIndex(fn);
findIndex([1, 2, 3, 4], x => x % 2); ... | code_snippets | ||
dac75ca8-0b3d-401b-a44c-2b12aeb1f10b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-has-only-one-match-or-many.md | unknown | 2b77b3fa-7554-4a14-8149-48a7b489701b | 0 | SemanticChunker@1.0.0 | d7f30608872f149f7b6ac5262870d3f877aac67eb61d29e5e292dfecad7519ac | ---
title: Check if a JavaScript array has only one or many matches
shortTitle: Array has only one or many matches
language: javascript
tags: [array]
cover: interior-10
excerpt: Learn how to check if an array has one or more values matching the given function, and how to find the matching elements.
listed: true
dateMod... | unknown | unknown | ---
title: Check if a JavaScript array has only one or many matches
shortTitle: Array has only one or many matches
language: javascript
tags: [array]
cover: interior-10
excerpt: Learn how to check if an array has one or more values matching the given function, and how to find the matching elements.
listed: true
dateMod... | ---
title: Check if a JavaScript array has only one or many matches
shortTitle: Array has only one or many matches
language: javascript
tags: [array]
cover: interior-10
excerpt: Learn how to check if an array has one or more values matching the given function, and how to find the matching elements.
listed: true
dateMod... | code_snippets | ||
ecff6d0a-51ea-4002-a221-1bda98601274 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-has-only-one-match-or-many.md | unknown | 2b77b3fa-7554-4a14-8149-48a7b489701b | 4 | SemanticChunker@1.0.0 | 9d577808717f15a8a0e75a9b8150af8c583903fd458323f380d1d865787b247a | [Check if an array has only one match > Find all indexes of the matching elements]
## Find all indexes of the matching elements
Finding the indexes of all matching elements is a little more involved. You need to use `Array.prototype.reduce()` to loop over elements and store the indexes of matching elements.
```js
co... | unknown | unknown | [Check if an array has only one match > Find all indexes of the matching elements]
## Find all indexes of the matching elements
Finding the indexes of all matching elements is a little more involved. You need to use `Array.prototype.reduce()` to loop over elements and store the indexes of matching elements.
```js
co... | [Check if an array has only one match > Find all indexes of the matching elements]
## Find all indexes of the matching elements
Finding the indexes of all matching elements is a little more involved. You need to use `Array.prototype.reduce()` to loop over elements and store the indexes of matching elements.
```js
co... | code_snippets | ||
fad7a93b-bc56-4020-b4b9-19b843e0e7fe | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-has-only-one-match-or-many.md | unknown | 2b77b3fa-7554-4a14-8149-48a7b489701b | 1 | SemanticChunker@1.0.0 | 7a50b22d43c5658d7943b025443bbaf5de876dd637b9fcc4c0593002b1c63748 | [Check if an array has only one match]
## Check if an array has only one match
Using `Array.prototype.filter()` and `Array.prototype.length`, you can easily check if an array has only one value matching the given function.
```js
const hasOne = (arr, fn) => arr.filter(fn).length === 1;
hasOne([1, 2], x => x % 2); //... | unknown | unknown | [Check if an array has only one match]
## Check if an array has only one match
Using `Array.prototype.filter()` and `Array.prototype.length`, you can easily check if an array has only one value matching the given function.
```js
const hasOne = (arr, fn) => arr.filter(fn).length === 1;
hasOne([1, 2], x => x % 2); //... | [Check if an array has only one match]
## Check if an array has only one match
Using `Array.prototype.filter()` and `Array.prototype.length`, you can easily check if an array has only one value matching the given function.
```js
const hasOne = (arr, fn) => arr.filter(fn).length === 1;
hasOne([1, 2], x => x % 2); //... | code_snippets | ||
2c3c8fa3-ec0a-4bf7-98d8-977633577d85 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-comparison.md | unknown | 4e8511cb-f332-43bc-b9f2-915e3afd054d | 4 | SemanticChunker@1.0.0 | 39d22951a3b91d8759d10f5b2ea9c42d77c96650885f41bdaf43fdfdde1e2bcc | [Equality comparison > Comparing out of order]
## Comparing out of order
Finally, there are cases where the order of the elements in each array is not important and we only care about the same values existing in both arrays. For these cases, you can use `Set` and `Array.prototype.filter()` in combination with a loop ... | unknown | unknown | [Equality comparison > Comparing out of order]
## Comparing out of order
Finally, there are cases where the order of the elements in each array is not important and we only care about the same values existing in both arrays. For these cases, you can use `Set` and `Array.prototype.filter()` in combination with a loop ... | [Equality comparison > Comparing out of order]
## Comparing out of order
Finally, there are cases where the order of the elements in each array is not important and we only care about the same values existing in both arrays. For these cases, you can use `Set` and `Array.prototype.filter()` in combination with a loop ... | code_snippets | ||
5154fc8f-8dfb-4fa9-aabf-2fd8b1bd0649 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-comparison.md | unknown | 4e8511cb-f332-43bc-b9f2-915e3afd054d | 3 | SemanticChunker@1.0.0 | 46a17e3ec74e369303623d4c90947fee415940f965822c8fdd6160ae28536bca | [Equality comparison > A better way]
## A better way
A better approach would be to compare the two arrays' `length`s and use `Array.prototype.every()` to compare the values of the two:
```js
const equals = (a, b) =>
a.length === b.length &&
a.every((v, i) => v === b[i]);
const a = [1, 2, 3];
const b = [1, 2, 3];
... | unknown | unknown | [Equality comparison > A better way]
## A better way
A better approach would be to compare the two arrays' `length`s and use `Array.prototype.every()` to compare the values of the two:
```js
const equals = (a, b) =>
a.length === b.length &&
a.every((v, i) => v === b[i]);
const a = [1, 2, 3];
const b = [1, 2, 3];
... | [Equality comparison > A better way]
## A better way
A better approach would be to compare the two arrays' `length`s and use `Array.prototype.every()` to compare the values of the two:
```js
const equals = (a, b) =>
a.length === b.length &&
a.every((v, i) => v === b[i]);
const a = [1, 2, 3];
const b = [1, 2, 3];
... | code_snippets | ||
a0074a69-050e-4ad2-8c1e-6f5c413de24a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-comparison.md | unknown | 4e8511cb-f332-43bc-b9f2-915e3afd054d | 1 | SemanticChunker@1.0.0 | 82c834af8bdb2d679b1df3dd6d9f027818b41b13fed1f4ad846bb53d83c6a882 | [Equality comparison]
## Equality comparison
Comparing two arrays in JavaScript using either the loose or strict equality operators (`==` or `===`) will most often result in `false`, even if the two arrays contain the same elements in the same order. This is due to the fact that arrays and objects are compared by ref... | unknown | unknown | [Equality comparison]
## Equality comparison
Comparing two arrays in JavaScript using either the loose or strict equality operators (`==` or `===`) will most often result in `false`, even if the two arrays contain the same elements in the same order. This is due to the fact that arrays and objects are compared by ref... | [Equality comparison]
## Equality comparison
Comparing two arrays in JavaScript using either the loose or strict equality operators (`==` or `===`) will most often result in `false`, even if the two arrays contain the same elements in the same order. This is due to the fact that arrays and objects are compared by ref... | code_snippets | ||
ba790db8-9226-4145-b375-1d22702c1b79 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-comparison.md | unknown | 4e8511cb-f332-43bc-b9f2-915e3afd054d | 0 | SemanticChunker@1.0.0 | 4b26c5f5ae087314e6cf5b09a44702d6d9a7eaa7c6061ce57af495cd9b886f21 | ---
title: How do I compare two arrays in JavaScript?
shortTitle: JavaScript array comparison
language: javascript
tags: [array,comparison]
cover: coconuts
excerpt: Learn how you can compare two arrays in JavaScript using various different techniques.
listed: true
dateModified: 2021-09-27
--- | unknown | unknown | ---
title: How do I compare two arrays in JavaScript?
shortTitle: JavaScript array comparison
language: javascript
tags: [array,comparison]
cover: coconuts
excerpt: Learn how you can compare two arrays in JavaScript using various different techniques.
listed: true
dateModified: 2021-09-27
--- | ---
title: How do I compare two arrays in JavaScript?
shortTitle: JavaScript array comparison
language: javascript
tags: [array,comparison]
cover: coconuts
excerpt: Learn how you can compare two arrays in JavaScript using various different techniques.
listed: true
dateModified: 2021-09-27
--- | code_snippets | ||
c9bfd74c-e3ee-4ac5-8a51-76d6f5568ea3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-comparison.md | unknown | 4e8511cb-f332-43bc-b9f2-915e3afd054d | 2 | SemanticChunker@1.0.0 | ae6807f47b310117c5b3d7e6d68bd8a4d88aebe5a74d133f05c4131fe32ad4f8 | [Equality comparison > JSON.stringify]
## JSON.stringify
A common solution that many people suggest is to use `JSON.stringify()`. This allows us to serialize each array and then compare the two serialized strings. A simple implementation of this might look something like this:
```js
const equals = (a, b) => JSON.str... | unknown | unknown | [Equality comparison > JSON.stringify]
## JSON.stringify
A common solution that many people suggest is to use `JSON.stringify()`. This allows us to serialize each array and then compare the two serialized strings. A simple implementation of this might look something like this:
```js
const equals = (a, b) => JSON.str... | [Equality comparison > JSON.stringify]
## JSON.stringify
A common solution that many people suggest is to use `JSON.stringify()`. This allows us to serialize each array and then compare the two serialized strings. A simple implementation of this might look something like this:
```js
const equals = (a, b) => JSON.str... | code_snippets | ||
322e80f2-b5fc-4e47-8cb9-9e66f386b26f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/arithmetic-and-geometric-progression.md | unknown | f9f10c9d-e168-4347-9a66-dcf796c53159 | 2 | SemanticChunker@1.0.0 | 00027839595e3287a16ec2d6f5fe19ad4dcc696d43dbdcc974a30b1e99dd3914 | [Arithmetic progression > Geometric progression]
## Geometric progression
Given a positive integer `end`, and optional positive integers `start` and `step`, the task is to create an array of numbers in the geometric progression, starting with the given positive integer and up to the specified limit.
In order to do s... | unknown | unknown | [Arithmetic progression > Geometric progression]
## Geometric progression
Given a positive integer `end`, and optional positive integers `start` and `step`, the task is to create an array of numbers in the geometric progression, starting with the given positive integer and up to the specified limit.
In order to do s... | [Arithmetic progression > Geometric progression]
## Geometric progression
Given a positive integer `end`, and optional positive integers `start` and `step`, the task is to create an array of numbers in the geometric progression, starting with the given positive integer and up to the specified limit.
In order to do s... | code_snippets | ||
54d3d7d6-ad5b-47e4-8af6-8b48fdd75219 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/arithmetic-and-geometric-progression.md | unknown | f9f10c9d-e168-4347-9a66-dcf796c53159 | 0 | SemanticChunker@1.0.0 | 2df1c0e85b4051d7f1eaaef1e4f5ba6dd3ae8d8e52b683ce93c2899f5d3b6148 | ---
title: Arithmetic and geometric progression in JavaScript
shortTitle: Arithmetic and geometric progression
language: javascript
tags: [math,algorithm]
cover: half-trees
excerpt: Create arrays of numbers in arithmetic and geometric progression.
listed: true
dateModified: 2024-02-16
---
Arithmetic progression refers... | unknown | unknown | ---
title: Arithmetic and geometric progression in JavaScript
shortTitle: Arithmetic and geometric progression
language: javascript
tags: [math,algorithm]
cover: half-trees
excerpt: Create arrays of numbers in arithmetic and geometric progression.
listed: true
dateModified: 2024-02-16
---
Arithmetic progression refers... | ---
title: Arithmetic and geometric progression in JavaScript
shortTitle: Arithmetic and geometric progression
language: javascript
tags: [math,algorithm]
cover: half-trees
excerpt: Create arrays of numbers in arithmetic and geometric progression.
listed: true
dateModified: 2024-02-16
---
Arithmetic progression refers... | code_snippets | ||
95671c3b-5798-4da4-8c05-71e4153a9c11 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/arithmetic-and-geometric-progression.md | unknown | f9f10c9d-e168-4347-9a66-dcf796c53159 | 1 | SemanticChunker@1.0.0 | e872004a491423032954ff4ee6859d1b6e130e90bf121f5e7c64b21369a62e78 | [Arithmetic progression]
## Arithmetic progression
Given a positive integer `n` and a positive limit `lim`, the task is to create an array of numbers in the arithmetic progression, starting with the given positive integer and up to the specified limit.
In order to do so, you can use `Array.from()` to create an array... | unknown | unknown | [Arithmetic progression]
## Arithmetic progression
Given a positive integer `n` and a positive limit `lim`, the task is to create an array of numbers in the arithmetic progression, starting with the given positive integer and up to the specified limit.
In order to do so, you can use `Array.from()` to create an array... | [Arithmetic progression]
## Arithmetic progression
Given a positive integer `n` and a positive limit `lim`, the task is to create an array of numbers in the arithmetic progression, starting with the given positive integer and up to the specified limit.
In order to do so, you can use `Array.from()` to create an array... | code_snippets | ||
3005deb8-5160-43d8-b966-15a0c6660a9b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/approximately-equal.md | unknown | 94464694-b430-4027-9742-f43e4fbb0bf0 | 0 | SemanticChunker@1.0.0 | 3ef5b03a1dca2acb7ed7c3e56a8d8cb9eff01dcb74dcfd2be08aa36d3d210b17 | ---
title: Check if two numbers are approximately equal in JavaScript
shortTitle: Approximate number equality
language: javascript
tags: [math]
cover: female-hiker
excerpt: Learn how to check if two numbers are approximately equal to each other in JavaScript.
listed: true
dateModified: 2024-02-04
---
We've all seen th... | unknown | unknown | ---
title: Check if two numbers are approximately equal in JavaScript
shortTitle: Approximate number equality
language: javascript
tags: [math]
cover: female-hiker
excerpt: Learn how to check if two numbers are approximately equal to each other in JavaScript.
listed: true
dateModified: 2024-02-04
---
We've all seen th... | ---
title: Check if two numbers are approximately equal in JavaScript
shortTitle: Approximate number equality
language: javascript
tags: [math]
cover: female-hiker
excerpt: Learn how to check if two numbers are approximately equal to each other in JavaScript.
listed: true
dateModified: 2024-02-04
---
We've all seen th... | code_snippets | ||
4f0a48be-8e61-4073-af2e-e65ef3ddda12 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-remove-multiple-event-listeners-single-element.md | unknown | 6852e1b8-1b04-48c7-a881-4cd355a60e71 | 1 | SemanticChunker@1.0.0 | cba2593398965a4f6e0165b8cd7e1ee95b5cbdb0fb0badee1f8ce31e2d4e5fd2 | [Add multiple event listeners to an element]
## Add multiple event listeners to an element
All you need is a helper function that adds multiple event listeners with the same handler to an element. Using `Array.prototype.forEach()` and `EventTarget.addEventListener()`, you can attach multiple event listeners with an a... | unknown | unknown | [Add multiple event listeners to an element]
## Add multiple event listeners to an element
All you need is a helper function that adds multiple event listeners with the same handler to an element. Using `Array.prototype.forEach()` and `EventTarget.addEventListener()`, you can attach multiple event listeners with an a... | [Add multiple event listeners to an element]
## Add multiple event listeners to an element
All you need is a helper function that adds multiple event listeners with the same handler to an element. Using `Array.prototype.forEach()` and `EventTarget.addEventListener()`, you can attach multiple event listeners with an a... | code_snippets | ||
9d7ae5e7-8e84-49d5-9aff-f78d7b6c723c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-remove-multiple-event-listeners-single-element.md | unknown | 6852e1b8-1b04-48c7-a881-4cd355a60e71 | 2 | SemanticChunker@1.0.0 | bf1174edb5037a592cf94576464914f9faee204eb40124a0dc2cb606e59070f6 | [Add multiple event listeners to an element > Remove multiple event listeners from an element]
## Remove multiple event listeners from an element
Similarly, you can create a helper function that removes multiple event listeners with the same handler from an element, using the same approach as before. The only differe... | unknown | unknown | [Add multiple event listeners to an element > Remove multiple event listeners from an element]
## Remove multiple event listeners from an element
Similarly, you can create a helper function that removes multiple event listeners with the same handler from an element, using the same approach as before. The only differe... | [Add multiple event listeners to an element > Remove multiple event listeners from an element]
## Remove multiple event listeners from an element
Similarly, you can create a helper function that removes multiple event listeners with the same handler from an element, using the same approach as before. The only differe... | code_snippets | ||
a848b072-c371-48fe-aecf-54848fed7e52 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-remove-multiple-event-listeners-single-element.md | unknown | 6852e1b8-1b04-48c7-a881-4cd355a60e71 | 0 | SemanticChunker@1.0.0 | 9961a48ebe83f29e0e561f4abb2f22bd651e6e7aa1f39e08a90eb3e43c733e3f | ---
title: Add or remove multiple event listeners from a single element
shortTitle: Add or remove multiple event listeners
language: javascript
tags: [browser,event]
cover: compass-1
excerpt: Ever wanted to listen for multiple events on an element and handle them with the same function? Here's how!
listed: true
dateMod... | unknown | unknown | ---
title: Add or remove multiple event listeners from a single element
shortTitle: Add or remove multiple event listeners
language: javascript
tags: [browser,event]
cover: compass-1
excerpt: Ever wanted to listen for multiple events on an element and handle them with the same function? Here's how!
listed: true
dateMod... | ---
title: Add or remove multiple event listeners from a single element
shortTitle: Add or remove multiple event listeners
language: javascript
tags: [browser,event]
cover: compass-1
excerpt: Ever wanted to listen for multiple events on an element and handle them with the same function? Here's how!
listed: true
dateMod... | code_snippets | ||
1eb4a468-bf42-4450-b302-a2765c3d89fd | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/append-elements-to-array.md | unknown | 86250188-480b-47c6-a19b-53b2e0c08bbe | 1 | SemanticChunker@1.0.0 | c7f151ffbdce13da4075b8e68c9c25154298cf6ca36cf9e20bee133fd2974a56 | [Array.prototype.push()]
## Array.prototype.push()
The classical way to append elements to the end of an array is to use `Array.prototype.push()`. While versatile, you need to remember that it **mutates the original array**. On the flip side, it supports adding multiple elements at once. Finally, the return value of ... | unknown | unknown | [Array.prototype.push()]
## Array.prototype.push()
The classical way to append elements to the end of an array is to use `Array.prototype.push()`. While versatile, you need to remember that it **mutates the original array**. On the flip side, it supports adding multiple elements at once. Finally, the return value of ... | [Array.prototype.push()]
## Array.prototype.push()
The classical way to append elements to the end of an array is to use `Array.prototype.push()`. While versatile, you need to remember that it **mutates the original array**. On the flip side, it supports adding multiple elements at once. Finally, the return value of ... | code_snippets | ||
4bf5eefd-3bd9-4be5-b12d-e43eb623b6f2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/append-elements-to-array.md | unknown | 86250188-480b-47c6-a19b-53b2e0c08bbe | 3 | SemanticChunker@1.0.0 | 9e1f4e335c61feb1810c4c6411b56e38904bd396ae9f99623be6627b0196d3ee | [Array.prototype.push() > Array.prototype.splice()]
## Array.prototype.splice()
`Array.prototype.splice()` is more often used for removing elements from an array, but it can append elements, too. While it also **mutates the original array**, it can append elements anywhere in the array. Similar to previous methods, i... | unknown | unknown | [Array.prototype.push() > Array.prototype.splice()]
## Array.prototype.splice()
`Array.prototype.splice()` is more often used for removing elements from an array, but it can append elements, too. While it also **mutates the original array**, it can append elements anywhere in the array. Similar to previous methods, i... | [Array.prototype.push() > Array.prototype.splice()]
## Array.prototype.splice()
`Array.prototype.splice()` is more often used for removing elements from an array, but it can append elements, too. While it also **mutates the original array**, it can append elements anywhere in the array. Similar to previous methods, i... | code_snippets | ||
76893194-77e1-4532-a17f-a59ba36cdd37 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/append-elements-to-array.md | unknown | 86250188-480b-47c6-a19b-53b2e0c08bbe | 2 | SemanticChunker@1.0.0 | def34652233d4d3b5583c84c8f796f16d003e0ad70a5313794cd5a921cf0e34e | [Array.prototype.push() > Array.prototype.unshift()]
## Array.prototype.unshift()
Similar to `Array.prototype.push()`, `Array.prototype.unshift()` appends elements to the start of an array. Furthermore, this method also **mutates the original array** and supports adding multiple elements at once.
```js
const arr = [... | unknown | unknown | [Array.prototype.push() > Array.prototype.unshift()]
## Array.prototype.unshift()
Similar to `Array.prototype.push()`, `Array.prototype.unshift()` appends elements to the start of an array. Furthermore, this method also **mutates the original array** and supports adding multiple elements at once.
```js
const arr = [... | [Array.prototype.push() > Array.prototype.unshift()]
## Array.prototype.unshift()
Similar to `Array.prototype.push()`, `Array.prototype.unshift()` appends elements to the start of an array. Furthermore, this method also **mutates the original array** and supports adding multiple elements at once.
```js
const arr = [... | code_snippets | ||
87425ca5-b959-487f-8e3b-3f96c4682a94 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/append-elements-to-array.md | unknown | 86250188-480b-47c6-a19b-53b2e0c08bbe | 4 | SemanticChunker@1.0.0 | 523e39a0766331252ec93ba07c4173e73d0f24b7a437b834e1afe3e2ea039bc5 | [Array.prototype.push() > Array.prototype.length]
## Array.prototype.length
Appending an element to the end of an array means setting a value for an index equal to its length. This is due to arrays in JavaScript being zero-indexed. Luckily, `Array.prototype.length` can be combined with array index notation to accompl... | unknown | unknown | [Array.prototype.push() > Array.prototype.length]
## Array.prototype.length
Appending an element to the end of an array means setting a value for an index equal to its length. This is due to arrays in JavaScript being zero-indexed. Luckily, `Array.prototype.length` can be combined with array index notation to accompl... | [Array.prototype.push() > Array.prototype.length]
## Array.prototype.length
Appending an element to the end of an array means setting a value for an index equal to its length. This is due to arrays in JavaScript being zero-indexed. Luckily, `Array.prototype.length` can be combined with array index notation to accompl... | code_snippets | ||
98aeb444-190d-45ea-8ba7-b43bfb051f40 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/append-elements-to-array.md | unknown | 86250188-480b-47c6-a19b-53b2e0c08bbe | 5 | SemanticChunker@1.0.0 | 0246474fcdda62c8d17b25b51fa99f6b9aa1f077f7487a17dd29d746a965721a | [Array.prototype.push() > Array.prototype.concat()]
## Array.prototype.concat()
The first option that **doesn't mutate the original array** is `Array.prototype.concat()`. This method returns a new array with the elements of the original array and new elements concatenated to it. It can be used to append elements to e... | unknown | unknown | [Array.prototype.push() > Array.prototype.concat()]
## Array.prototype.concat()
The first option that **doesn't mutate the original array** is `Array.prototype.concat()`. This method returns a new array with the elements of the original array and new elements concatenated to it. It can be used to append elements to e... | [Array.prototype.push() > Array.prototype.concat()]
## Array.prototype.concat()
The first option that **doesn't mutate the original array** is `Array.prototype.concat()`. This method returns a new array with the elements of the original array and new elements concatenated to it. It can be used to append elements to e... | code_snippets | ||
9e54b9d5-be4e-4624-97cb-03ba2e00b39f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/append-elements-to-array.md | unknown | 86250188-480b-47c6-a19b-53b2e0c08bbe | 6 | SemanticChunker@1.0.0 | dbbb6a47e16db5213463e2522ea29b9102b3fa9eb2140a6136674b8956f0554a | [Array.prototype.push() > Spread operator]
## Spread operator
Finally, the last option that **doesn't mutate the original array** is the spread operator (`...`). The way that it works is essentially the same as `Array.prototype.concat()`, supporting appending one or more elements to either end of the array.
```js
co... | unknown | unknown | [Array.prototype.push() > Spread operator]
## Spread operator
Finally, the last option that **doesn't mutate the original array** is the spread operator (`...`). The way that it works is essentially the same as `Array.prototype.concat()`, supporting appending one or more elements to either end of the array.
```js
co... | [Array.prototype.push() > Spread operator]
## Spread operator
Finally, the last option that **doesn't mutate the original array** is the spread operator (`...`). The way that it works is essentially the same as `Array.prototype.concat()`, supporting appending one or more elements to either end of the array.
```js
co... | code_snippets | ||
aa7da662-678f-4861-99f4-0413048fdf38 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/append-elements-to-array.md | unknown | 86250188-480b-47c6-a19b-53b2e0c08bbe | 0 | SemanticChunker@1.0.0 | c23ef1f991cd1058930724a9d0698be8d7bf24ccca3bbf116b4c799c2a4e6ea1 | ---
title: Append elements to a JavaScript array
shortTitle: Append elements to array
language: javascript
tags: [array]
cover: switzerland-night
excerpt: Have you ever tried appending elements to an array in JavaScript? Here's a primer on all the available options.
listed: true
dateModified: 2022-07-10
---
Appending ... | unknown | unknown | ---
title: Append elements to a JavaScript array
shortTitle: Append elements to array
language: javascript
tags: [array]
cover: switzerland-night
excerpt: Have you ever tried appending elements to an array in JavaScript? Here's a primer on all the available options.
listed: true
dateModified: 2022-07-10
---
Appending ... | ---
title: Append elements to a JavaScript array
shortTitle: Append elements to array
language: javascript
tags: [array]
cover: switzerland-night
excerpt: Have you ever tried appending elements to an array in JavaScript? Here's a primer on all the available options.
listed: true
dateModified: 2022-07-10
---
Appending ... | code_snippets | ||
014b3bc4-a8ef-4997-be38-a5ddf18ed57c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-remove-event-listener.md | unknown | c0ab353c-3cf7-49e7-8ee9-11c567f2c43c | 3 | SemanticChunker@1.0.0 | a73012774cb4dff1e03f8ba1589ed8df63c74d9c536401f6371540120d111da4 | [Add event listener > Remove event listener]
## Remove event listener
Removing an event listener from an element is as easy as adding one, maybe even easier. You can use the `EventTarget.removeEventListener()` method to **remove an event listener** from an element.
Defining a reusable function, `off`, for listener r... | unknown | unknown | [Add event listener > Remove event listener]
## Remove event listener
Removing an event listener from an element is as easy as adding one, maybe even easier. You can use the `EventTarget.removeEventListener()` method to **remove an event listener** from an element.
Defining a reusable function, `off`, for listener r... | [Add event listener > Remove event listener]
## Remove event listener
Removing an event listener from an element is as easy as adding one, maybe even easier. You can use the `EventTarget.removeEventListener()` method to **remove an event listener** from an element.
Defining a reusable function, `off`, for listener r... | code_snippets | ||
09836ffe-3280-4d99-9c94-6e00f02c4b81 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-remove-event-listener.md | unknown | c0ab353c-3cf7-49e7-8ee9-11c567f2c43c | 1 | SemanticChunker@1.0.0 | e6a2f17842a273f3c7fca2276b32b45b2911426a68ee05e2eb196be9a8373b4c | [Add event listener]
## Add event listener
In order to **add an event listener** to an element, you can use the `EventTarget.addEventListener()` method. Yet, in some cases, adding a listener for every single element can be a bit of a **performance** hit. In these cases, you can use [event delegation](/js/s/event-bubb... | unknown | unknown | [Add event listener]
## Add event listener
In order to **add an event listener** to an element, you can use the `EventTarget.addEventListener()` method. Yet, in some cases, adding a listener for every single element can be a bit of a **performance** hit. In these cases, you can use [event delegation](/js/s/event-bubb... | [Add event listener]
## Add event listener
In order to **add an event listener** to an element, you can use the `EventTarget.addEventListener()` method. Yet, in some cases, adding a listener for every single element can be a bit of a **performance** hit. In these cases, you can use [event delegation](/js/s/event-bubb... | code_snippets | ||
b1b225e8-29a8-460e-8e50-92dbca0ef4fb | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-remove-event-listener.md | unknown | c0ab353c-3cf7-49e7-8ee9-11c567f2c43c | 2 | SemanticChunker@1.0.0 | 1822da6bbcc26741c1eb23845f344cc25149dcf3cfb28579b98e0ecb1d69bd9d | [Add event listener]
```js
const on = (el, evt, fn, opts = {}) => {
const delegatorFn = e =>
e.target.matches(opts.target) && fn.call(e.target, e);
el.addEventListener(
evt,
opts.target ? delegatorFn : fn,
opts.options || false
);
if (opts.target) return delegatorFn;
};
const fn = () => console.log('!');
on(... | unknown | unknown | [Add event listener]
```js
const on = (el, evt, fn, opts = {}) => {
const delegatorFn = e =>
e.target.matches(opts.target) && fn.call(e.target, e);
el.addEventListener(
evt,
opts.target ? delegatorFn : fn,
opts.options || false
);
if (opts.target) return delegatorFn;
};
const fn = () => console.log('!');
on(... | [Add event listener]
```js
const on = (el, evt, fn, opts = {}) => {
const delegatorFn = e =>
e.target.matches(opts.target) && fn.call(e.target, e);
el.addEventListener(
evt,
opts.target ? delegatorFn : fn,
opts.options || false
);
if (opts.target) return delegatorFn;
};
const fn = () => console.log('!');
on(... | code_snippets | ||
bd86f26d-810d-4922-a018-2a83a7d0e098 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-remove-event-listener.md | unknown | c0ab353c-3cf7-49e7-8ee9-11c567f2c43c | 0 | SemanticChunker@1.0.0 | 861d5dec8338acebc07a2b3ede320f879714b4dc2e8ce4620ec84c3a80f07a7a | ---
title: Add or remove an event listener in JavaScript
shortTitle: Add or remove event listener
language: javascript
tags: [browser,event]
cover: wooden-bowl
excerpt: Learn how to add or remove event listeners from elements with ease.
listed: true
dateModified: 2023-10-28
--- | unknown | unknown | ---
title: Add or remove an event listener in JavaScript
shortTitle: Add or remove event listener
language: javascript
tags: [browser,event]
cover: wooden-bowl
excerpt: Learn how to add or remove event listeners from elements with ease.
listed: true
dateModified: 2023-10-28
--- | ---
title: Add or remove an event listener in JavaScript
shortTitle: Add or remove event listener
language: javascript
tags: [browser,event]
cover: wooden-bowl
excerpt: Learn how to add or remove event listeners from elements with ease.
listed: true
dateModified: 2023-10-28
--- | code_snippets | ||
ccc8da85-f442-4906-93ca-4bf71670abcd | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-remove-event-listener.md | unknown | c0ab353c-3cf7-49e7-8ee9-11c567f2c43c | 4 | SemanticChunker@1.0.0 | 2584d45feee95366d03bc1eac837c41c85f845cb80f72d6649cc02d6088f372a | [Remove event listener > Notes]
### Notes
These functions are written in a way that somewhat mimics jQuery's [`on`](https://api.jquery.com/on/) and [`off`](https://api.jquery.com/off/) methods. They are not meant as a replacement, but rather as a way to use a similar syntax without having to include jQuery in your pr... | unknown | unknown | [Remove event listener > Notes]
### Notes
These functions are written in a way that somewhat mimics jQuery's [`on`](https://api.jquery.com/on/) and [`off`](https://api.jquery.com/off/) methods. They are not meant as a replacement, but rather as a way to use a similar syntax without having to include jQuery in your pr... | [Remove event listener > Notes]
### Notes
These functions are written in a way that somewhat mimics jQuery's [`on`](https://api.jquery.com/on/) and [`off`](https://api.jquery.com/off/) methods. They are not meant as a replacement, but rather as a way to use a similar syntax without having to include jQuery in your pr... | code_snippets | ||
27fe40cb-3bf6-4645-a8f7-e651879f3a5f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-remove-event-listener-multiple-elements.md | unknown | e8425c9d-4d18-49ee-a842-7b8c6a0acd72 | 2 | SemanticChunker@1.0.0 | 00f7dc902c08cb1aed408565d642db289290fe813787b35427a7bcde88e0e18d | [Add event listener to multiple elements > Remove event listener from multiple elements]
## Remove event listener from multiple elements
Similarly, removing the same event listener from multiple elements can be done by iterating over the elements with `Array.prototype.forEach()` and detaching the listener using `Even... | unknown | unknown | [Add event listener to multiple elements > Remove event listener from multiple elements]
## Remove event listener from multiple elements
Similarly, removing the same event listener from multiple elements can be done by iterating over the elements with `Array.prototype.forEach()` and detaching the listener using `Even... | [Add event listener to multiple elements > Remove event listener from multiple elements]
## Remove event listener from multiple elements
Similarly, removing the same event listener from multiple elements can be done by iterating over the elements with `Array.prototype.forEach()` and detaching the listener using `Even... | code_snippets | ||
7d3e0ceb-8dc8-4559-858b-06a9f35edd5a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-remove-event-listener-multiple-elements.md | unknown | e8425c9d-4d18-49ee-a842-7b8c6a0acd72 | 0 | SemanticChunker@1.0.0 | 39291c70e10d5df0209c9370fbd730d8b57390a4e61c4e64089f8eb21769759b | ---
title: How can I add or remove an event listener from multiple elements?
shortTitle: Add or remove event listener from multiple elements
language: javascript
tags: [browser,event]
cover: duck-plants
excerpt: Level up your event handling skills by learning how to attach or detach event listeners from multiple elemen... | unknown | unknown | ---
title: How can I add or remove an event listener from multiple elements?
shortTitle: Add or remove event listener from multiple elements
language: javascript
tags: [browser,event]
cover: duck-plants
excerpt: Level up your event handling skills by learning how to attach or detach event listeners from multiple elemen... | ---
title: How can I add or remove an event listener from multiple elements?
shortTitle: Add or remove event listener from multiple elements
language: javascript
tags: [browser,event]
cover: duck-plants
excerpt: Level up your event handling skills by learning how to attach or detach event listeners from multiple elemen... | code_snippets | ||
d171db75-5567-4afb-a4ff-2d2e9408ef54 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/add-remove-event-listener-multiple-elements.md | unknown | e8425c9d-4d18-49ee-a842-7b8c6a0acd72 | 1 | SemanticChunker@1.0.0 | ce4af386a98f71ffa14a961914cf56977fba49c1f52660701837eb851a9952c4 | [Add event listener to multiple elements]
## Add event listener to multiple elements
If all you need to do is add the same event listener to multiple elements, you can use `Array.prototype.forEach()` to iterate over the elements and attach the listener using `EventTarget.addEventListener()`.
You will need to provide... | unknown | unknown | [Add event listener to multiple elements]
## Add event listener to multiple elements
If all you need to do is add the same event listener to multiple elements, you can use `Array.prototype.forEach()` to iterate over the elements and attach the listener using `EventTarget.addEventListener()`.
You will need to provide... | [Add event listener to multiple elements]
## Add event listener to multiple elements
If all you need to do is add the same event listener to multiple elements, you can use `Array.prototype.forEach()` to iterate over the elements and attach the listener using `EventTarget.addEventListener()`.
You will need to provide... | code_snippets | ||
62df52ac-0fab-463d-bc7c-9f47ab3a627b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/all-values-of-array-are-equal.md | unknown | 6f10e48e-3aa2-470f-9cd0-c4fc87ba9c0b | 1 | SemanticChunker@1.0.0 | 2d5da5ff2df5b168bc8450db901c714eb1a3533b1575cec49d00c81e535d117c | [Comparing array elements by value]
## Comparing array elements by value
Using `Array.prototype.every()` is what comes to mind and it's the right path to go down. As we need to compare all elements to each other, we can just use the **first element** as the reference and compare the rest of the array to it.
```js
co... | unknown | unknown | [Comparing array elements by value]
## Comparing array elements by value
Using `Array.prototype.every()` is what comes to mind and it's the right path to go down. As we need to compare all elements to each other, we can just use the **first element** as the reference and compare the rest of the array to it.
```js
co... | [Comparing array elements by value]
## Comparing array elements by value
Using `Array.prototype.every()` is what comes to mind and it's the right path to go down. As we need to compare all elements to each other, we can just use the **first element** as the reference and compare the rest of the array to it.
```js
co... | code_snippets | ||
79c37ce1-f90f-4bde-97d8-7dbb8d804040 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/all-values-of-array-are-equal.md | unknown | 6f10e48e-3aa2-470f-9cd0-c4fc87ba9c0b | 2 | SemanticChunker@1.0.0 | fb3b59db230abb58054d07cd451efaa6433efeb17e86578b558f8c81b7bc7486 | [Comparing array elements by value > Comparing array elements using a mapping function]
## Comparing array elements using a mapping function
For more complex values, such as objects, you might want to use a **mapping function** to compare the elements. This way, you can compare the elements based on a specific proper... | unknown | unknown | [Comparing array elements by value > Comparing array elements using a mapping function]
## Comparing array elements using a mapping function
For more complex values, such as objects, you might want to use a **mapping function** to compare the elements. This way, you can compare the elements based on a specific proper... | [Comparing array elements by value > Comparing array elements using a mapping function]
## Comparing array elements using a mapping function
For more complex values, such as objects, you might want to use a **mapping function** to compare the elements. This way, you can compare the elements based on a specific proper... | code_snippets | ||
94712cbb-6545-4097-bb2d-7df7723df1d0 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/all-values-of-array-are-equal.md | unknown | 6f10e48e-3aa2-470f-9cd0-c4fc87ba9c0b | 0 | SemanticChunker@1.0.0 | 0f24a3f3fe7275a1b05abd8b8d6b9b2f140b026eac197eda4556ec30f52f8bb4 | ---
title: Check if all values of a JavaScript array are equal
shortTitle: All array values are equal
language: javascript
tags: [array]
cover: book-stopper
excerpt: Use the `Array.prototype.every()` method to check if all values of an array are equal in JavaScript.
listed: true
dateModified: 2024-02-16
---
Checking i... | unknown | unknown | ---
title: Check if all values of a JavaScript array are equal
shortTitle: All array values are equal
language: javascript
tags: [array]
cover: book-stopper
excerpt: Use the `Array.prototype.every()` method to check if all values of an array are equal in JavaScript.
listed: true
dateModified: 2024-02-16
---
Checking i... | ---
title: Check if all values of a JavaScript array are equal
shortTitle: All array values are equal
language: javascript
tags: [array]
cover: book-stopper
excerpt: Use the `Array.prototype.every()` method to check if all values of an array are equal in JavaScript.
listed: true
dateModified: 2024-02-16
---
Checking i... | code_snippets | ||
220f0d56-5741-47fe-b543-be09c1f15779 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-or-string-permutations.md | unknown | 635d8e31-320f-45fa-a635-2cb995b67231 | 0 | SemanticChunker@1.0.0 | 2fb4cfadd48c7264063bbe2d177ae620773d17e6da8f67ec133da6cfb72b41f0 | ---
title: Calculate all permutations of a JavaScript array or string
shortTitle: Array or string permutations
language: javascript
tags: [array,string,recursion]
cover: body-of-water
excerpt: Generate all permutations of an array's elements or a string's characters using recursion.
listed: true
dateModified: 2024-02-0... | unknown | unknown | ---
title: Calculate all permutations of a JavaScript array or string
shortTitle: Array or string permutations
language: javascript
tags: [array,string,recursion]
cover: body-of-water
excerpt: Generate all permutations of an array's elements or a string's characters using recursion.
listed: true
dateModified: 2024-02-0... | ---
title: Calculate all permutations of a JavaScript array or string
shortTitle: Array or string permutations
language: javascript
tags: [array,string,recursion]
cover: body-of-water
excerpt: Generate all permutations of an array's elements or a string's characters using recursion.
listed: true
dateModified: 2024-02-0... | code_snippets | ||
2584619c-628a-46d5-adc0-c209c7f89382 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-or-string-permutations.md | unknown | 635d8e31-320f-45fa-a635-2cb995b67231 | 2 | SemanticChunker@1.0.0 | 772f8588d6e795f2b1546d171131b319d354b9fe00ced68153f8c333dac78e8b | [Array permutations > String permutations]
## String permutations
A similar technique can be used for a string. The base cases are identical and the algorithm is generally the same. The only significant difference is the use of `String.prototype.split()` to **convert the string into an array** of characters, and `Str... | unknown | unknown | [Array permutations > String permutations]
## String permutations
A similar technique can be used for a string. The base cases are identical and the algorithm is generally the same. The only significant difference is the use of `String.prototype.split()` to **convert the string into an array** of characters, and `Str... | [Array permutations > String permutations]
## String permutations
A similar technique can be used for a string. The base cases are identical and the algorithm is generally the same. The only significant difference is the use of `String.prototype.split()` to **convert the string into an array** of characters, and `Str... | code_snippets | ||
e866d890-e2eb-45c6-9b7d-a765ec22069b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-or-string-permutations.md | unknown | 635d8e31-320f-45fa-a635-2cb995b67231 | 1 | SemanticChunker@1.0.0 | 278bb856de6dc3105beb2b25c2c3b2c0aa5fc845aff3546665bbc4261d2013a3 | [Array permutations]
## Array permutations
Using recursion, we can generate all permutations of an array's elements, **including duplicates**. The **base cases** for the recursive function are when the array's length is equal to `2` or `1`. In this case, we return the array itself or an array with the elements swappe... | unknown | unknown | [Array permutations]
## Array permutations
Using recursion, we can generate all permutations of an array's elements, **including duplicates**. The **base cases** for the recursive function are when the array's length is equal to `2` or `1`. In this case, we return the array itself or an array with the elements swappe... | [Array permutations]
## Array permutations
Using recursion, we can generate all permutations of an array's elements, **including duplicates**. The **base cases** for the recursive function are when the array's length is equal to `2` or `1`. In this case, we return the array itself or an array with the elements swappe... | code_snippets | ||
0f90bba4-52d2-43ad-89aa-7bc48ecda51d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-map-vs-foreach.md | unknown | 0d4a0033-b7c6-462e-a809-21f7c48ed680 | 1 | SemanticChunker@1.0.0 | 627c1bf3e9c466c6839af2e73b6cd6c3137566ccb3e70d97d675e8888eb793ec | As a closing note, I would like to remind you that the humble `for` loop can be more efficient in some cases, such as [breaking out of a loop early](/js/s/for-loop-early-break). Always pick the right tool for the job, as ES6 has a method for almost every use case. | unknown | unknown | As a closing note, I would like to remind you that the humble `for` loop can be more efficient in some cases, such as [breaking out of a loop early](/js/s/for-loop-early-break). Always pick the right tool for the job, as ES6 has a method for almost every use case. | As a closing note, I would like to remind you that the humble `for` loop can be more efficient in some cases, such as [breaking out of a loop early](/js/s/for-loop-early-break). Always pick the right tool for the job, as ES6 has a method for almost every use case. | code_snippets | ||
e13f73b4-827a-4660-84f2-5b69682874f9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-map-vs-foreach.md | unknown | 0d4a0033-b7c6-462e-a809-21f7c48ed680 | 0 | SemanticChunker@1.0.0 | c708ee738e65e352d2fb3c5e84f0d0966f2315f88e7c060158083eb0253af60b | ---
title: What is the difference between Array.prototype.map() and Array.prototype.forEach()?
shortTitle: Array.prototype.map() vs Array.prototype.forEach()
language: javascript
tags: [array]
cover: fort-lamp
excerpt: Which method do you reach for first? What are the differences between them? Let's find out!
listed: t... | unknown | unknown | ---
title: What is the difference between Array.prototype.map() and Array.prototype.forEach()?
shortTitle: Array.prototype.map() vs Array.prototype.forEach()
language: javascript
tags: [array]
cover: fort-lamp
excerpt: Which method do you reach for first? What are the differences between them? Let's find out!
listed: t... | ---
title: What is the difference between Array.prototype.map() and Array.prototype.forEach()?
shortTitle: Array.prototype.map() vs Array.prototype.forEach()
language: javascript
tags: [array]
cover: fort-lamp
excerpt: Which method do you reach for first? What are the differences between them? Let's find out!
listed: t... | code_snippets | ||
08189e07-2b4f-4d7f-a4cf-7cf160629e11 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-min-max.md | unknown | 1df10d39-ae33-48f7-81e7-ae1d2e2cf583 | 2 | SemanticChunker@1.0.0 | 2ec7a261db1a7e11f90c03cdbecc11905141502e1d939f1015d6bca21bcede54 | [Min & max value of a numeric array > N min & max values of a numeric array]
## N min & max values of a numeric array
What if you need to find the `n` minimum or maximum values? Turns out it's almost as easy.
For either one of the operations, we'll first need to **sort the array in ascending or descending order**. T... | unknown | unknown | [Min & max value of a numeric array > N min & max values of a numeric array]
## N min & max values of a numeric array
What if you need to find the `n` minimum or maximum values? Turns out it's almost as easy.
For either one of the operations, we'll first need to **sort the array in ascending or descending order**. T... | [Min & max value of a numeric array > N min & max values of a numeric array]
## N min & max values of a numeric array
What if you need to find the `n` minimum or maximum values? Turns out it's almost as easy.
For either one of the operations, we'll first need to **sort the array in ascending or descending order**. T... | code_snippets | ||
b98070bc-368e-486c-a4bd-f530a3510aab | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-min-max.md | unknown | 1df10d39-ae33-48f7-81e7-ae1d2e2cf583 | 1 | SemanticChunker@1.0.0 | 37a3a26a4a4f05620df993ceb3bde9d9ca45c401a4fa3e3fa3266802788d4197 | [Min & max value of a numeric array]
## Min & max value of a numeric array
When working with numeric arrays in JavaScript, you might find yourself in need of finding the **minimum** or **maximum** value. Luckily, JavaScript's `Math` built-in object has got you covered. You can simply use `Math.min()` or `Math.max()` ... | unknown | unknown | [Min & max value of a numeric array]
## Min & max value of a numeric array
When working with numeric arrays in JavaScript, you might find yourself in need of finding the **minimum** or **maximum** value. Luckily, JavaScript's `Math` built-in object has got you covered. You can simply use `Math.min()` or `Math.max()` ... | [Min & max value of a numeric array]
## Min & max value of a numeric array
When working with numeric arrays in JavaScript, you might find yourself in need of finding the **minimum** or **maximum** value. Luckily, JavaScript's `Math` built-in object has got you covered. You can simply use `Math.min()` or `Math.max()` ... | code_snippets | ||
d4bf9bea-3598-4c81-924d-25c30c6d90fc | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-min-max.md | unknown | 1df10d39-ae33-48f7-81e7-ae1d2e2cf583 | 0 | SemanticChunker@1.0.0 | cccfad5ad26e009ea191b6a4c6dbedece63bd56ef065038c3612514c1394d9c7 | ---
title: Min and max value of a JavaScript array
shortTitle: Min and max value of an array
language: javascript
tags: [array,math]
cover: little-tree
excerpt: When working with JavaScript arrays, you might need the minimum or maximum value. Here are a few quick and easy ways to do it.
listed: true
dateModified: 2023-... | unknown | unknown | ---
title: Min and max value of a JavaScript array
shortTitle: Min and max value of an array
language: javascript
tags: [array,math]
cover: little-tree
excerpt: When working with JavaScript arrays, you might need the minimum or maximum value. Here are a few quick and easy ways to do it.
listed: true
dateModified: 2023-... | ---
title: Min and max value of a JavaScript array
shortTitle: Min and max value of an array
language: javascript
tags: [array,math]
cover: little-tree
excerpt: When working with JavaScript arrays, you might need the minimum or maximum value. Here are a few quick and easy ways to do it.
listed: true
dateModified: 2023-... | code_snippets | ||
dbe09ddf-6954-4257-94c8-05b844a5e571 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-min-max.md | unknown | 1df10d39-ae33-48f7-81e7-ae1d2e2cf583 | 3 | SemanticChunker@1.0.0 | 8f6ab7859303105940db633be3f7f963e1a36ddb4857d31e3cd4dc5d25538ef1 | [Min & max value of a numeric array > Min & max value of an array based on function]
## Min & max value of an array based on function
For more complex cases, such as finding the min/max value in an **array of objects**, you will have to use `Array.prototype.map()`. Given an **appropriate function** or a **property na... | unknown | unknown | [Min & max value of a numeric array > Min & max value of an array based on function]
## Min & max value of an array based on function
For more complex cases, such as finding the min/max value in an **array of objects**, you will have to use `Array.prototype.map()`. Given an **appropriate function** or a **property na... | [Min & max value of a numeric array > Min & max value of an array based on function]
## Min & max value of an array based on function
For more complex cases, such as finding the min/max value in an **array of objects**, you will have to use `Array.prototype.map()`. Given an **appropriate function** or a **property na... | code_snippets | ||
bdb71b41-5584-4d5f-b136-0dcf6a1b64da | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-ranking.md | unknown | 31452b7b-27fb-4533-8250-367883332bb1 | 0 | SemanticChunker@1.0.0 | 5f304884b80efca68b12eefc649ddd855346f62b1d124cdf8217429cf1e2efe4 | ---
title: Calculate the ranking of a JavaScript array
shortTitle: Array ranking
language: javascript
tags: [array,math]
cover: eagle
excerpt: Calculate the ranking of an array based on a comparator function in JavaScript.
listed: true
dateModified: 2024-02-16
---
The **ranking** of an array is a list of the **positio... | unknown | unknown | ---
title: Calculate the ranking of a JavaScript array
shortTitle: Array ranking
language: javascript
tags: [array,math]
cover: eagle
excerpt: Calculate the ranking of an array based on a comparator function in JavaScript.
listed: true
dateModified: 2024-02-16
---
The **ranking** of an array is a list of the **positio... | ---
title: Calculate the ranking of a JavaScript array
shortTitle: Array ranking
language: javascript
tags: [array,math]
cover: eagle
excerpt: Calculate the ranking of an array based on a comparator function in JavaScript.
listed: true
dateModified: 2024-02-16
---
The **ranking** of an array is a list of the **positio... | code_snippets | ||
3a51931c-32db-4a32-b952-77cce6ca24c5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-sample-shuffle-weighted-selection.md | unknown | 78fee289-c93d-42e7-9900-88e2a1952d07 | 2 | SemanticChunker@1.0.0 | a41378b6f245d710810e1904d61c8a2684cd6aa06f72f132646b8803cec33c15 | [Shuffle an array > Sample a random element from an array]
## Sample a random element from an array
Getting a random element from an array is as simple as generating a **random index** and returning the element at that index. To calculate the index, you can use `Math.random()` and `Array.prototype.length` to generate... | unknown | unknown | [Shuffle an array > Sample a random element from an array]
## Sample a random element from an array
Getting a random element from an array is as simple as generating a **random index** and returning the element at that index. To calculate the index, you can use `Math.random()` and `Array.prototype.length` to generate... | [Shuffle an array > Sample a random element from an array]
## Sample a random element from an array
Getting a random element from an array is as simple as generating a **random index** and returning the element at that index. To calculate the index, you can use `Math.random()` and `Array.prototype.length` to generate... | code_snippets | ||
3fa09a0a-0773-4c87-9993-67bbb7b1e456 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-sample-shuffle-weighted-selection.md | unknown | 78fee289-c93d-42e7-9900-88e2a1952d07 | 4 | SemanticChunker@1.0.0 | 5f101d862d6aa9ce728f925db0fbc40fd93d22699e3ccb27be1d011ebb6fc63f | [Shuffle an array > Weighted sample from an array]
## Weighted sample from an array
A more advanced use cases might involve weighted selection, where the **probability** of each element being selected is provided upfront. In order for this to work, you can use `Array.prototype.reduce()` to create an **array of partia... | unknown | unknown | [Shuffle an array > Weighted sample from an array]
## Weighted sample from an array
A more advanced use cases might involve weighted selection, where the **probability** of each element being selected is provided upfront. In order for this to work, you can use `Array.prototype.reduce()` to create an **array of partia... | [Shuffle an array > Weighted sample from an array]
## Weighted sample from an array
A more advanced use cases might involve weighted selection, where the **probability** of each element being selected is provided upfront. In order for this to work, you can use `Array.prototype.reduce()` to create an **array of partia... | code_snippets | ||
812620a6-b58d-4cd0-862c-b62ead6eb27a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-sample-shuffle-weighted-selection.md | unknown | 78fee289-c93d-42e7-9900-88e2a1952d07 | 1 | SemanticChunker@1.0.0 | 707717ea9e38492d67cb0cb15ba2fafeed2fcee8b99894c47e3b5a9742f1c35d | [Shuffle an array]
## Shuffle an array
Using `Math.random()` to shuffle an array seems like the obvious solution, yet it's **heavily biased and not recommended**. Instead, you can use the [Fisher-Yates algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Fisher_and_Yates'_original_method) to reorder ... | unknown | unknown | [Shuffle an array]
## Shuffle an array
Using `Math.random()` to shuffle an array seems like the obvious solution, yet it's **heavily biased and not recommended**. Instead, you can use the [Fisher-Yates algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Fisher_and_Yates'_original_method) to reorder ... | [Shuffle an array]
## Shuffle an array
Using `Math.random()` to shuffle an array seems like the obvious solution, yet it's **heavily biased and not recommended**. Instead, you can use the [Fisher-Yates algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Fisher_and_Yates'_original_method) to reorder ... | code_snippets | ||
8ae5d771-5e00-4a6b-9f77-943ca619c5f7 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-sample-shuffle-weighted-selection.md | unknown | 78fee289-c93d-42e7-9900-88e2a1952d07 | 0 | SemanticChunker@1.0.0 | 31877e03c9d54b75fd68b0a035337b74e238c8c95943918f3774088b6d0a9edd | ---
title: Sampling, shuffling and weighted selection in JavaScript arrays
shortTitle: Sample, shuffle and weighted selection
language: javascript
tags: [array,random]
cover: blue-bench
excerpt: Learn how to shuffle, sample and perform weighted selection on JavaScript arrays.
listed: true
dateModified: 2024-03-15
---
... | unknown | unknown | ---
title: Sampling, shuffling and weighted selection in JavaScript arrays
shortTitle: Sample, shuffle and weighted selection
language: javascript
tags: [array,random]
cover: blue-bench
excerpt: Learn how to shuffle, sample and perform weighted selection on JavaScript arrays.
listed: true
dateModified: 2024-03-15
---
... | ---
title: Sampling, shuffling and weighted selection in JavaScript arrays
shortTitle: Sample, shuffle and weighted selection
language: javascript
tags: [array,random]
cover: blue-bench
excerpt: Learn how to shuffle, sample and perform weighted selection on JavaScript arrays.
listed: true
dateModified: 2024-03-15
---
... | code_snippets | ||
a1262f7d-1d7e-487c-b42f-7a65ac182d7e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-sample-shuffle-weighted-selection.md | unknown | 78fee289-c93d-42e7-9900-88e2a1952d07 | 3 | SemanticChunker@1.0.0 | 1ddf759fd3aa693fcb9848d939fe6c222f5575982cdb64af3714175c69433c4b | [Shuffle an array > Sample multiple random elements from an array]
## Sample multiple random elements from an array
Sampling multiple elements is a little more involved. Using the **shuffle** function provided above, you can use `Array.prototype.slice()` to get the first `n` elements from the shuffled array. If you d... | unknown | unknown | [Shuffle an array > Sample multiple random elements from an array]
## Sample multiple random elements from an array
Sampling multiple elements is a little more involved. Using the **shuffle** function provided above, you can use `Array.prototype.slice()` to get the first `n` elements from the shuffled array. If you d... | [Shuffle an array > Sample multiple random elements from an array]
## Sample multiple random elements from an array
Sampling multiple elements is a little more involved. Using the **shuffle** function provided above, you can use `Array.prototype.slice()` to get the first `n` elements from the shuffled array. If you d... | code_snippets | ||
286800a7-2920-4307-a1cd-a6145e9299f1 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-includes-value.md | unknown | 77128e79-d7e2-4f18-83dc-af4d4168d4ec | 1 | SemanticChunker@1.0.0 | fd3b6dc72bfcc82a9292594d5a150332777154b45ab87b172293fdcba2e3d097 | [Primitive values]
## Primitive values
You can use `Array.prototype.includes()` to check if an array contains a **primitive value**. This is the most convenient option when working with strings, numbers, booleans, symbols, `null` or `undefined`. You can even specify an **index** as a secondary parameter to start sear... | unknown | unknown | [Primitive values]
## Primitive values
You can use `Array.prototype.includes()` to check if an array contains a **primitive value**. This is the most convenient option when working with strings, numbers, booleans, symbols, `null` or `undefined`. You can even specify an **index** as a secondary parameter to start sear... | [Primitive values]
## Primitive values
You can use `Array.prototype.includes()` to check if an array contains a **primitive value**. This is the most convenient option when working with strings, numbers, booleans, symbols, `null` or `undefined`. You can even specify an **index** as a secondary parameter to start sear... | code_snippets | ||
ad552ab0-18a1-4fa8-919b-e3759d0f1871 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-includes-value.md | unknown | 77128e79-d7e2-4f18-83dc-af4d4168d4ec | 2 | SemanticChunker@1.0.0 | d70453a357907a92206ed79c88fd6bca4c64f4241986687430fa5954e520df90 | [Primitive values > Objects]
## Objects
Unlike primitive values, you can't use `Array.prototype.includes()` to check if an array includes an object. This comes down to how JavaScript compares values and the fact that [objects are reference types](/js/s/pass-by-reference-or-pass-by-value). I highly recommend reading t... | unknown | unknown | [Primitive values > Objects]
## Objects
Unlike primitive values, you can't use `Array.prototype.includes()` to check if an array includes an object. This comes down to how JavaScript compares values and the fact that [objects are reference types](/js/s/pass-by-reference-or-pass-by-value). I highly recommend reading t... | [Primitive values > Objects]
## Objects
Unlike primitive values, you can't use `Array.prototype.includes()` to check if an array includes an object. This comes down to how JavaScript compares values and the fact that [objects are reference types](/js/s/pass-by-reference-or-pass-by-value). I highly recommend reading t... | code_snippets | ||
adf2e0c6-374e-430f-9675-72c41698f44b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-includes-value.md | unknown | 77128e79-d7e2-4f18-83dc-af4d4168d4ec | 0 | SemanticChunker@1.0.0 | 991470ad5b723a003d5e0c31b110ec61df8b813fdb05890866a8867ee01f775b | ---
title: How can I check if a JavaScript array includes a specific value?
shortTitle: Array includes value
language: javascript
tags: [array]
cover: bridge-drop
excerpt: Checking if an array includes a specific value is pretty straightforward, except when it comes to objects.
listed: true
dateModified: 2022-09-18
--- | unknown | unknown | ---
title: How can I check if a JavaScript array includes a specific value?
shortTitle: Array includes value
language: javascript
tags: [array]
cover: bridge-drop
excerpt: Checking if an array includes a specific value is pretty straightforward, except when it comes to objects.
listed: true
dateModified: 2022-09-18
--- | ---
title: How can I check if a JavaScript array includes a specific value?
shortTitle: Array includes value
language: javascript
tags: [array]
cover: bridge-drop
excerpt: Checking if an array includes a specific value is pretty straightforward, except when it comes to objects.
listed: true
dateModified: 2022-09-18
--- | code_snippets | ||
4b427c05-6d06-4ab7-a4a9-2628c32ff9d5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/array-is-sorted.md | unknown | 06272572-8675-439f-b1a3-34ab0ed77829 | 0 | SemanticChunker@1.0.0 | 37f129c8345d06c9e3840119d36ceb41b5082647ddf20b93fb49ae191c390ae2 | ---
title: Check if a numeric array is sorted in JavaScript
shortTitle: Array is sorted
language: javascript
tags: [array]
cover: italian-horizon
excerpt: Efficiently check if a numeric array is sorted in ascending or descending order in JavaScript.
listed: true
dateModified: 2024-02-15
---
Sometimes, it's useful to k... | unknown | unknown | ---
title: Check if a numeric array is sorted in JavaScript
shortTitle: Array is sorted
language: javascript
tags: [array]
cover: italian-horizon
excerpt: Efficiently check if a numeric array is sorted in ascending or descending order in JavaScript.
listed: true
dateModified: 2024-02-15
---
Sometimes, it's useful to k... | ---
title: Check if a numeric array is sorted in JavaScript
shortTitle: Array is sorted
language: javascript
tags: [array]
cover: italian-horizon
excerpt: Efficiently check if a numeric array is sorted in ascending or descending order in JavaScript.
listed: true
dateModified: 2024-02-15
---
Sometimes, it's useful to k... | code_snippets |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.