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

Bek*_*kki 2 javascript jquery

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

www.abc.com/product.html?product=furniture&&images=true&&stocks=yes
Run Code Online (Sandbox Code Playgroud)

我希望能够得到3的答案 1. product=furniture 2. images=true 3. stocks=yes

var url = window.location.href;
var arr = url.split('=');
console.log(url.length)
Run Code Online (Sandbox Code Playgroud)

hin*_*ost 7

您可以使用String的match

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