在javascript中保留动态值

时间:2017-11-19 00:32:14

标签: javascript jquery arrays

我想追加从后端获得的值。例如:

// Initially 

var x = '';

// on choosing first filter

x = v.state; (v.state value changes each time when filter is choosen, I want to append all the filter values choosen)



// output expected

x = firstFilter + '+' + secondFilter

现在我需要将所有过滤器值连接到“+”

1 个答案:

答案 0 :(得分:0)

构建一个数组并使用join运算符来拼接元素" +"



// Initially 

var x = [];

// on choosing first filter

x.push("A^B");

// on choosing second filter

x.push("C^D");

// output expected

console.log(x.join(" + "))

// A^B + C^D