检索字符串某个元素的前后(待完善)

64 阅读1分钟

使用 indexOf 和 substr

使用indexOf 检索出你需要的元素

let point = this.checkList.amount.indexOf(".")
           

使用substr 检索出你需要的元素的前和后

// 小数点后面
let pointBehind = this.checkList.amount.substr(point + 1);
// 小数点前面
let pointFront = this.checkList.amount.substring(0, point)