这在PHP中运行良好,我如何在JS / jQuery中完成相同的工作?
$statsArr['Status'][$s_id]['count'] = ($statsArr['Status'][$s_id]['count'] ?? 0) + 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