0

I have a string

and I want the get the second character from this string

// with a normal string the result is
var normalString = "abc"
normalString[1] // -> b
// but with this one the reslt is 
var weirdString = ""
weirdString[1] // -> � I get this "replacement charactere" instead of 
SkwalExe
  • 28
  • 2
  • 6

1 Answers1

1

1) You can use spread syntax here to spread string into an array

const weirdStringArr = [...weirdString];

2) Access the UNICODE symbol using index

weirdStringArr[1]

var weirdString = "";
const weirdStringArr = [...weirdString];
console.log(weirdStringArr[1]);
DecPK
  • 24,537
  • 6
  • 26
  • 42
  • 1
    Anyway it's a dupe - interestingly the dupe is using the same gothic alphabet. – mplungjan Oct 03 '21 at 08:53
  • 1
    @SkwalDev - The above is sufficient for a lot of use cases, but if the character ("glyph" would be the more accurate word) uses *combining marks*, even the above won't be sufficient because the glyph is made up of multiple unicode code points. Your string doesn't have that problem, but just beware of the possibility. – T.J. Crowder Oct 03 '21 at 08:53