-2

I'm having this error:

Object doesn't support 'from' property or method

on the following line:

const ids = Array.from(cbs).map(function(cb) {cb.getAttribute("data-item-id")});

How can I fix it?

a_l_e_x
  • 408
  • 1
  • 6
  • 20

2 Answers2

0

Array.from is not implemented in IE11, so you'll need to use a polyfill

spender
  • 117,338
  • 33
  • 229
  • 351
  • Therefore? how should i formulate my row? – a_l_e_x Feb 08 '22 at 12:46
  • @elfuso You add [the code that I linked to in the MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#polyfill) that will patch `Array`, adding support for `Array.from` – spender Feb 08 '22 at 12:48
  • @elfuso If you use a polyfill, it means you don't need to change any of your code, you just need to make sure the polyfill is loaded before your code. PS: always use a polyfill if available, as modifying code to cope with this browser that browser is not fun. – Keith Feb 08 '22 at 12:49
  • @elfuso I would also look into some form of transpiling, like babel / or Typescript, as you could even then do `[...cbs].map(` instead.. And transpiling will often add polyfills for you automatically. – Keith Feb 08 '22 at 12:53
0

Array from is not supported by IE https://caniuse.com/mdn-javascript_builtins_array_from

https://caniuse.com/ is you best friend in these cases.

Use a following polyfill to make it work. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#polyfill

Sjaak Wish
  • 455
  • 5
  • 8