如何在JS / jQuery中编写这个php数组函数?

时间:2017-09-13 01:11:52

标签: javascript php jquery

这在PHP中运行良好,我如何在JS / jQuery中完成相同的工作?

$statsArr['Status'][$s_id]['count'] = ($statsArr['Status'][$s_id]['count'] ?? 0) + 1;

1 个答案:

答案 0 :(得分:1)

您必须将每个数组定义为数组。然后,您不会遇到missing ; before statement错误。

var s_id = 0;
var statsArr = Array();
statsArr['Status'] = Array();
statsArr['Status'][s_id] = Array();
statsArr['Status'][s_id]['count'] = statsArr['Status'][s_id]['count'] + 1 || 0;
// the result will be 0 since statsArr['Status'][s_id]['count'] was not defined previously