gpt4 book ai didi

javascript - 如何从字符串中获取字符数组?

转载 作者:IT老高 更新时间:2023-10-28 11:04:47 26 4
gpt4 key购买 nike

如何在 JavaScript 中将字符串转换为字符数组?

我正在考虑将 "Hello world!" 之类的字符串放入数组
['H','e','l','l','o','','w','o','r','l','d','!' ]

最佳答案

Note: This is not unicode compliant. "I💖U".split('') results in the 4 character array ["I", "�", "�", "u"] which can lead to dangerous bugs. See answers below for safe alternatives.

只需将其拆分为空字符串即可。

var output = "Hello world!".split('');
console.log(output);

String.prototype.split() MDN docs .

关于javascript - 如何从字符串中获取字符数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4547609/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com