这在PHP中效果很好,如何在JS / jQuery中完成相同的工作?
$statsArr['Status'][$s_id]['count'] = ($statsArr['Status'][$s_id]['count'] ?? 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
关于javascript - 如何在JS/jQuery中编写此php数组函数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46187386/