Skip to main content

Spread

ES6 中資料會因前後順序被覆蓋

含頭不含尾

array.slice(0,2)取得0往後至陣列第2個位置的value
const foo = ["a", "b", "c", "d", "e"];
//移除index位置的value
let index = 3;
const foo1 = [
//spread syntax
//串接2串slice
...foo.slice(0, index),
...foo.slice(index + 1)
];
console.log(foo1);

案例

spread
const bar = [1, 2, 3];
let key = "x";
let value = 10;
console.log({
...bar,
[key]: value,
});
spread
const bar = [1, 2, 3];
let key = "x";
let value = 10;
console.log({
...bar,
[key]: value,
});
<head>
<title>Nested Title</title>
<meta name="description" content="Nested component" />
</head>