js帮我把这个字符串分割成两个字符串image368b41e5cb5e45d3dac69c9c458428078affedeejpgimage4a62e716ab3d22d8596946d328ff888705293195jpg
你可以使用字符串的split方法将字符串分割成两个子字符串。
const str = '["image\/36\/8b41e5cb5e45d3dac69c9c458428078affedee.jpg","image\/4a\/62e716ab3d22d8596946d328ff888705293195.jpg"]';
const arr = str.split(',');
const firstString = arr[0].replace('[', '');
const secondString = arr[1].replace(']', '');
console.log(firstString); // "image\/36\/8b41e5cb5e45d3dac69c9c458428078affedee.jpg"
console.log(secondString); // "image\/4a\/62e716ab3d22d8596946d328ff888705293195.jpg"
首先,使用split方法将字符串按逗号分割成一个字符串数组。然后,使用replace方法去除第一个字符串的左方括号和第二个字符串的右方括号。最后,将两个子字符串存储在变量中,即可得到结果
原文地址: http://www.cveoy.top/t/topic/hJEw 著作权归作者所有。请勿转载和采集!