阵列5 阵列10
function declarations and so on. While object literals are the usual case for destructuring, remember that you can also destructure Arrays and Sets. Let's have a look at how destructuring is used for arrays and Sets! The usual case for destructuring is with an object literal: 函数声明等。 虽然对象文字是解构的通常情况,但请记住,您也可以解构数组和集合。 让我们看看如何对数组和集合使用解构! 进行销毁的通常情况是使用对象文字: const dict = { prop1: "one", prop2: "two" }; const { prop1, prop2 } = dict; // prop1 = "one" // prop2 = "two" The syntax for Array and Set destructuring is a bit different: const arr = ["uno", "dos"]; const [one, two] = arr; // one = "uno" // two = "dos" // Or more explicitly const [width, height] = [200, 400]; The destructuring syntax within iteration looks like: const items = [ ["one", "two"], ["three", "four"] ]; items.forEach(([uno, dos]) => { console.log(uno, dos); }); // "one", "two" // "three", "foor" You can also clone an array with destructuring: const arr = ["one", "two"]; const clone = [...arr]; You can also use commas to your advantage if you don't care about a given index of an array: const arr = [1, 2, 3, 4]; const [,,,four] = arr; // four === 4 Destructuring is awesome for skilled JavaScript developers and can be confusing to newcomers. Basic array destructuring doesn't mislead too much but iterating can be an ugly snippet. Taking a minute to see these reduced examples may help you too better understand the pattern.翻译自: https://davidwalsh.name/array-destructuring
阵列5 阵列10
相关资源:jdk-8u281-windows-x64.exe