1

TypeError: d.split("+").at is not a function. (In 'd.split("+").at(-1)', 'd.split("+").at' is undefined) enter image description here

while running react app on safari 14.1 i come across this error , but on safari latest versions and google chrome, react app is working fine.

i tried debugging the the error and i think it's from the bundle.js file, if not please correct me.

Samrajj k
  • 11
  • 2
  • You need Safari 15.4 or higher to use `.at()`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at#browser_compatibility, use `.pop()` or index using the length of the array `-1` – Nick Parsons Aug 09 '23 at 06:12
  • Welcome to Stack Overflow. Please include some of your source code and show what you've tried and what you want to achieve. See [how to ask a good question](https://stackoverflow.com/help/how-to-ask) – righteousness_wealth Aug 09 '23 at 07:10

1 Answers1

0

Taking a look at the Browser compatibility of .at() you can see that Safari version 15.4. or higher is required for both desktop and mobile in order to use .at().

Unfortunately, Babel doesn't seem to compile .at() down on lower Safari versions either.

Babel Playground

I'd recommend to use an alternative syntax that produces the same result such as array[array.length - 1], array.pop(), ... This might be helpful to find a suitable workaround: Get the last item in an array

Behemoth
  • 5,389
  • 4
  • 16
  • 40