The problem is that every time a string comes in with a different number of characters. But at the end of each line is the symbol "e". How to find this character without knowing the length of the string?
2 answers
The slice function can take a negative value, then the report will go from the end
var text = '134t8t103tu104ti13-э'; var lastChar = text.slice(-1); Well, either manually recognize the length of the line
var text = "1234135134uhkr9u94mэ"; var lastChar = text[text.length -1]; |
var stringValue = "dfsdfэ"; var letter = stringValue.split('').splice(-1).join(''); alert(letter); |