javascript - How i can create a new string with two reversed last letters of another string?
问题描述
I tried use conditional (Ternary) Operator but i dont know how to select just the last and second-last letters of string [enter image description here][1]
解决方案
Without just giving you the answer, if you're ever stuck with a Javascript problem in which you need to manipulate primitives(like string, number, etc.), I'd suggest you look into the methods available. Here is w3schools' list of string methods:
https://www.w3schools.com/jsref/jsref_obj_string.asp
In your case, you might first try the slice method:
https://www.w3schools.com/jsref/jsref_slice_string.asp
Then, you'll need a way to reverse the string. There's no clear string method for this but there are other approaches such as converting the string into an array, reversing the order of that array, then joining the array elements into a string. See here for solutions like that and others:
推荐阅读
- typescript - 为什么当 var 的类型是数字时,总和得到 NaN?
- operating-system - 在超级用户模式下不触发外部中断
- javascript - 从子级中排除嵌套组件(Nuxt 路由)
- java - 即使在spring boot中安装了maven,mvn命令也不起作用
- r - 通过 ggplot + coord_trans 进行 log2 变换的逆
- hbase - 如何在不退出 hbase shell 的情况下修复以星号结尾的提示?
- powerbi - 为什么 FILTER 中的 VALUES 会导致恢复过滤器?
- regex - Notepad++ - 如果条件为真,如何替换 1 个字符
- javascript - JavaScript - 大数的除法和乘法
- python - 元组的关键字是什么?