Skip to content

Instantly share code, notes, and snippets.

View gjlmotea's full-sized avatar

GJLMoTea gjlmotea

View GitHub Profile

Frameworks like React require that when you change the contents of an array or object you change its reference. Or push another way that you don't change arrays but instead create new arrays with updated values (i.e. immutability).

There are older array methods that are incompatible with immutability because they alter the array in place and don't change the array reference. These are mutable (or destructive) methods.

Shown below are replacements for the array destructive methods (e.g. push, pop, splice, sort, etc.) that will create new array references with the updated data.

Solutions are provided using the spread operator and also the newer "change array by copy" methods (toSpliced, toSorted, toReversed and with).

Setting Value At Index

@scmx
scmx / using-details-summary-github.md
Last active May 26, 2025 18:43
Using <details> <summary> expandable content on GitHub with Markdown #details #summary #markdown #gfm #html

How to use <details> <summary> expandable content on GitHub with Markdown

Firstly, what is <details> <summary>?

The HTML Details Element (<details>) creates a disclosure widget in which information is visible only when the widget is toggled into an "open" state. A summary or label can be provided using the <summary> element. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details.

Example

@pjchender
pjchender / Async Await 基本使用.js
Last active November 28, 2023 12:38
Promise and Async/Await Example
// async function 本身會回傳 Promise,
// 因此 async function 之後也可以用 `.then()` 串起來
main().then(value => {
console.log(value);
});
async function main () {
console.log('start fn') // STEP 1-1
let val = await get() // STEP 1-2