如何将数组中的数字拆分为单个数字

Ism*_*ail 0 javascript arrays numbers

在我的代码中,我收到一个包含数字的数组。有些数字是两位数甚至三位数。所以它看起来像这样:

\n
\xc2\xa0[48, 48, 48, 48, 99, 52, 50, 100, 97, 101, 102, 51, 98, 100, 49, 100, 51, 100, 52, 53, 54, 57, 99, 49, 53, 52, 55, 51, 55, 52, 100, 57, 99, 56, 52, 49, 99, 99, 102, 52, 56, 50, 51, 55, 53, 49, 56, 97, 53, 101, 99, 53, 55, 54, 99, 57, 50, 97, 99, 56, 97, 50, 53, 53, 49, 54, 52, 55, 50, 54, 56, 57, 56, 50, 54, 54, 57, 50, 53, 55, 48]\n
Run Code Online (Sandbox Code Playgroud)\n

这是我实现这一目标的代码:

\n
function hashData(s) {\nlet hashArray = []; \n\nfor(let i = 0; i < s.length; i++){\n    let code = s.charCodeAt(i);\n    hashArray.push(code);\n\n}\nhashArray.toString().split("")\nconsole.log(hashArray)\nreturn hashArray;\n
Run Code Online (Sandbox Code Playgroud)\n

}

\n

我想要实现的是:

\n
[4, 8, 4, 8, 4, 8, 4, 8, 9, 9, 5, 2] //and so on.\n
Run Code Online (Sandbox Code Playgroud)\n

正如你所看到的,我已经尝试过该toString()方法,但似乎没有任何作用。

\n

Nin*_*olz 5

您可以加入并获得一个新数组。

const
    values = [1, 23, 456, 7890],
    result = Array.from(values.join(''), Number);

console.log(result);
Run Code Online (Sandbox Code Playgroud)