const str = 'I am a student';
const {a,b,c,...oth} = str;
//方法一,运用ES6的结构赋值中的扩展运算符
const [ ...spStr1 ] = str;
console.log(spStr1);
//方法二,字符串的split方法
const spStr2 = str.split('');
//方法三,跟方法一差不多
const spStr3 = [ ...str ];
如何分解一个字符串?运用ES6的字符串解构赋值
最新推荐文章于 2023-02-22 17:07:32 发布