请问函数怎么返回数组多个值?JS

函数怎么返回数组内多个值?
const word =

('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 最后一个值

img

怎么返回 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


您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632