gpt4 book ai didi

javascript - 如何将字符串转换为数组

转载 作者:行者123 更新时间:2023-12-01 15:53:59 26 4
gpt4 key购买 nike

如何将这种格式的字符串 '[11, 66]' 转换为数组?

Array.isArray('[11, 66]') 返回 false 因为它被认为是字符串?

最佳答案

一个很好的方法是JSON.parse .

The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string.

在你的例子中:

JSON.parse('[11, 66]')

输出:

[11, 66]

关于javascript - 如何将字符串转换为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58867402/

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