This is working great in PHP, how can I accomplish the same in JS/jQuery?
$statsArr['Status'][$s_id]['count'] = ($statsArr['Status'][$s_id]['count'] ?? 0) + 1;
This is working great in PHP, how can I accomplish the same in JS/jQuery?
$statsArr['Status'][$s_id]['count'] = ($statsArr['Status'][$s_id]['count'] ?? 0) + 1;
You have to define each array as an array. Then you won't have the missing ; before statement
error.
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