Convert reduce function to work with IE

后端 未结 2 1331
小蘑菇
小蘑菇 2021-01-15 04:40

Alright, so I had some help a couple months ago with coming up with a solution to keep count of the elements in an array: Loop through multiple array and keep count of each

相关标签:
2条回答
  • 2021-01-15 05:12

    Remove the de-structuring.

    cur.ProductHandlingTypes.map((obj) => obj.Name).forEach(...
    
    0 讨论(0)
  • 2021-01-15 05:19

    IE 11 doesn't support arrow functions [1], nor destructuring [2], so convert it to ES5 syntax:

    var b = data.reduce(function(acc, cur) {
      cur.ProductHandlingTypes
        .map(function(obj) {
          return obj.Name
        })
        .forEach(function(n) {
          return acc[n] = (acc[n] || 0) + 1
        })
    
      return acc
    }, {});
    

    [1] http://caniuse.com/#feat=arrow-functions

    [2] http://kangax.github.io/compat-table/es6/#test-destructuring

    0 讨论(0)
提交回复
热议问题