分组和&总结在jQuery,javascript [英] group by & sum in jQuery, javascript
问题描述
以下格式有一些值
[[A,150,500,6000],[B,160,700,7000],[B,200,633,9000] ,[B,210,633,9000]]
i需要按照&总和
i需要最终输出为
A,150,500,6000
B,570,1966,2500
以上需要用java脚本或j查询来实现
https:// forums。 asp.net/p/2060010/5940708.aspx?p=True&t=635729744287236348 [ ^ ]
there are some values in below format
[[A,150,500,6000],[B,160,700,7000],[B,200,633,9000],[B,210,633,9000]]
i need to do group by & do sum
i need final output to be
A,150,500,6000
B,570,1966,2500
the above need to be achieved either with java script or j query
https://forums.asp.net/p/2060010/5940708.aspx?p=True&t=635729744287236348[^]
推荐答案
如果你只是定义A和B,你可以立即在JavaScript中使用它:
If you simply define A and B, you could use it in JavaScript immediately:
var A, B
var array = [[A,150,500,6000],[B,160,700,7000],[B,200,633,9000],[B,210,633,9000]]
// now you can access members directly:
var second = array[1]; // returns [B,160,700,7000]
var element = array[1][1]; // returns first number, 140
或者,您可以解析字符串,依此类推,但您只需将其用作 eval
调用的参数,并执行以上所有操作。
-SA
Alternatively, you can parse string, and so on, but you can simply use it as the argument of the call to eval
and do all of the above.
—SA
这篇关于分组和&总结在jQuery,javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!