要获取' - '前面的字符串,可以使用substring 方法。根据提供的字符串,找到第一个-的索引,然后使用substring 方法获取该索引之前的子字符串。以下是使用 JavaScript 代码实现的示例:

let str = 'bf20a4f5abaaf97c0027689467679744aa14-169381647333222';
let index = str.indexOf('-');
let result = str.substring(0, index);
console.log(result);

输出结果为:'bf20a4f5abaaf97c0027689467679744aa14'

JavaScript 获取字符串中'-' 前面的内容

原文地址: https://www.cveoy.top/t/topic/qFEW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录