简体   繁体   中英

Eslint warning about deconstruction

How would I use array destructuring on this. I'm getting a linter waring.

Use array destructuring. [prefer-destructuring]

const block = Object.entries(products).reduce((acc, item) => {
      acc[item[0]] = item[1];
      return acc;
    }, {}

);

Destructure item in the parameter list into [key, val] :

const block = Object.entries(products).reduce((acc, [key, val]) => {
  acc[key] = val;
  return acc;
}, {});

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.

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