ESLint recommended me to destructure below array to ES6 style(prefer-destructuring). 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]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.