gpt4 book ai didi

javascript - 计算查询字符串中参数的数量

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

如何计算传递的参数查询字符串的数量?例如

www.abc.com/product.html?product=furniture&&images=true&&stocks=yes

我希望能够得到答案 31。产品=家具2。图片=true3。股票=是

var url = window.location.href;
var arr = url.split('=');
console.log(url.length)

最佳答案

您可以使用字符串的匹配:

var matches = str.match(/[a-z\d]+=[a-z\d]+/gi);
var count = matches? matches.length : 0;

关于javascript - 计算查询字符串中参数的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32046990/

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