aiheyoghurt_ 2022-09-17 20:17 采纳率: 100%
浏览 31
已结题

请问函数怎么返回数组多个值?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 的所有值
  • 写回答

3条回答 默认 最新

  • CSDN专家-showbo 2022-09-17 21:05
    关注

    逗号操作符只返回最后的一个内容,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);
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 9月25日
  • 已采纳回答 9月17日
  • 创建了问题 9月17日

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起