('underscore_case',
'first_name',
'Some_Variable',
'calculate_AGE',
'delayed_departure');
const b = function () {
const d = word.split('\n');
for (const e of d) {
const [first, second] = e.toLowerCase().split('_');
const out = ${first}${second.replace(second[0], second[0].toUpperCase())}
;
console.log(out);
}
};
b(word);
逗号操作符只返回最后的一个内容,word直接申明为数组
,b函数里面直接用,不需要再split拆分为数组,示例如下
const word =
['underscore_case',
'first_name',
'Some_Variable',
'calculate_AGE',
'delayed_departure'];
const b = function () {
//const d = word.split('\n');
for (const e of word) {////////
const [first, second] = e.toLowerCase().split('_');
const out = `${first}${second.replace(second[0], second[0].toUpperCase())}`;
console.log(out);
}
};
b(word);
这样子定义只会取最终值
const word =
('underscore_case',
'first_name',
'Some_Variable',
'calculate_AGE',
'delayed_departure');
console.log('word的值:', word)
// word的值: delayed_departure
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!