简体   繁体   English

如何解构此数组?

[英]How can I destructure this array?

ESLint recommended me to destructure below array to ES6 style(prefer-destructuring). ESLint建议我将数组下方的结构分解为ES6样式(首选分解)。 Is it possible to destructure this? 有可能破坏它吗?

params[key] = params[key].split('?')[0];

With array destructuring, you put the left-hand side in [...] where each element corresponds to the element you want from the right-hand side. 通过数组解构,您可以将左侧放置在[...] ,其中每个元素都与您想要从右侧获得的元素相对应。 In this case, you just want the first element, so: 在这种情况下,您只需要第一个元素,因此:

[params[key]] = params[key].split('?');

Live Example: 现场示例:

 const params = { foo: "foo?bar" }; const key = "foo"; [params[key]] = params[key].split('?'); console.log(params[key]); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM