【问题标题】:Return Uint8Array from function从函数返回 Uint8Array
【发布时间】:2022-12-07 16:32:26
【问题描述】:

我正在尝试组合两个 Uint8Array 并在此函数中返回结果

commandframe = new Uint8Array([0x01,0x00]); GetCRC16Full(commandframe, true);

function GetCRC16Full(cmd, IsHighBefore) {
    let check= [0xff];

    var mergedArray = new Uint8Array(cmd.length + check.length);
    mergedArray.set(cmd);
    mergedArray.set(check, cmd.length);
    
    return mergedArray;

}

在 Vscode 调试模式下,我可以看到函数 mergedArray 是 [0x01,0x00,0xff],但返回后命令帧没有改变,这是为什么?

【问题讨论】:

    标签: javascript arrays function return uint8array


    【解决方案1】:

    你永远不会修改commandFramemergedArray 从函数返回但未分配给 commandFrame

    你可以试试这个:

    commandframe = new Uint8Array([0x01,0x00]); 
    commandframe = GetCRC16Full(commandframe, true);
    

    【讨论】:

      猜你喜欢
      • 2018-12-24
      • 2018-01-02
      • 1970-01-01
      • 1970-01-01
      • 2013-05-15
      • 2016-08-28
      • 2021-12-09
      • 2015-01-26
      • 2018-05-19
      相关资源
      最近更新 更多