Split string and then show all items without the last

前端 未结 2 371
时光说笑
时光说笑 2021-01-27 04:30

I have (for example) string like let abc = \'Jonny_Name\', so if i want to check, this is name or not I check:

let isName = abc.split(\'_\')[1];           


        
2条回答
  •  感动是毒
    2021-01-27 05:01

    const abc = 'Jonny_Great_Dude_Name';
    const splitted = abc.split(/_/);
    const [other, name] = [splitted.pop(), splitted.join('_')];
    console.log({name:name, isName: other == 'Name'});

提交回复
热议问题