C/C++教程

replaceAll is not a funtion

本文主要是介绍replaceAll is not a funtion,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

在这里插入图片描述

function randomSessionId() {
  let ua = new Uint8Array(20);
  new DataView(ua.buffer).setUint32(0, Math.floor(+new Date() / 1000));
  let crypto = window.crypto || window.msCrypto;
  if (crypto) {
    crypto.getRandomValues(ua.subarray(4, 20));
  }
  return (
    "1." +
    transformUint8ArrayToBase64(ua)
      .replaceAll("+", "-")
      .replaceAll("/", "_")
  );
}

解决方法为:

function randomSessionId() {
  let ua = new Uint8Array(20);
  new DataView(ua.buffer).setUint32(0, Math.floor(+new Date() / 1000));
  let crypto = window.crypto || window.msCrypto;
  if (crypto) {
    crypto.getRandomValues(ua.subarray(4, 20));
  }
  return (
    "1." +
    transformUint8ArrayToBase64(ua)
      .replace(/\+/g, "-")
      .replace(/\//g, "_")
  );
}

这篇关于replaceAll is not a funtion的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!