Quantcast
Channel: User Ben Aston - Stack Overflow
Viewing all articles
Browse latest Browse all 56

Answer by Ben Aston for Insert a string at a specific index

$
0
0
  1. Instantiate an array from the string
  2. Use Array#splice
  3. Stringify again using Array#join

The benefits of this approach are two-fold:

  1. Simple
  2. Unicode code point compliant

const pair = Array.from('USDGBP')pair.splice(3, 0, '/')console.log(pair.join(''))

Viewing all articles
Browse latest Browse all 56

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>