【发布时间】:2018-12-06 09:59:48
【问题描述】:
我有如下字符串格式的变量:
"hello?supporterId=57d7466d"
我想从上面的字符串中提取supporterId和hello text的值如下:
text="hello"
supporterId="57d7466d"
如何在javascript中实现这一点?
【问题讨论】:
-
发布的问题似乎根本没有包含any attempt 来解决问题。 StackOverflow 期待您 try to solve your own problem first,因为您的尝试有助于我们更好地了解您想要什么。请编辑问题以显示您尝试过的内容,以说明您遇到minimal reproducible example 的特定障碍。欲了解更多信息,请参阅How to Ask 并拨打tour。
-
使用
split或regEx -
如果此字符串是 url 的一部分,您可以使用
URLSearchParams和window.location属性来提取信息,而无需自己解析。
标签: javascript string url