0

I'm not so good at javascript and it's replace, so I'm wondering if you can optimize this line (etc one .replace instead of two):

$itemClicked.replace(/ä|å/g, 'a').replace(/ö/g, 'o');
Marwelln
  • 28,492
  • 21
  • 93
  • 117

1 Answers1

1

This should be the best possible if you only need to replace just these 3 letters. Using 1 .replace is possible, but it must use a function, e.g.

$itemClicked.replace(/[äåö]/g, function(s) { return s=='ö'?'o':'a'; });

See JavaScript: Efficiently replace all accented characters in a string? for a generalization.

Community
  • 1
  • 1
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005