我在javascript中使用以下格式的字符串,
acadYear=self.request.get_all('acadYear')[0].encode('UTF-8')
我需要从 str 中拆分并获取a中的Itemid值,b中的名称值,dept值c。如何在javascript中执行此操作?
答案 0 :(得分:0)
var a = "";var b ="";var c= "";
var str = "ItemID=123&Name=AO Document&Value=Testvalue";
// split the string at the '&' and '=' characters, but use only those parts with odd indices
var parts = str.split(/[&=]/).filter((_, i) => i % 2 === 1);
// assign the values to a, b and c using destructuring
[a, b, c] = parts;
console.log(a, b, c);