Reputation: 1360
ESLint recommended me to destructure below array to ES6 style(prefer-destructuring). Is it possible to destructure this?
params[key] = params[key].split('?')[0];
Upvotes: 1
Views: 497
Reputation: 1075039
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]);
Upvotes: 5