如何使用 javascript 获取字符串中的所有多引号文本

How to get all the multiple quoted text inside a string using javascript

我有一个 var s = '["hi","hello","What\'s new"]'; 格式的 string 变量。 我如何分别获取值 hi hello What's new
变量 s 中的值也是动态的,有时它可能是 var s = '["wow","okay"]'; 或任何值。
有人可以帮我解决这个问题吗?

首先,这段代码有错误var s = '["hi","hello","What's new"]'需要写成var s = '["hi","hello","What\'s new"]'否则会报错:

Uncaught SyntaxError: Unexpected identifier

如果您正在寻找这样的输出:

["hi","hello","What's new"]

那么这是解决方案:

var s = '["hi","hello","What\'s new"]'
console.log(JSON.parse(s))