BUGFIX: Uncaught SyntaxError expected expression, got ')'
PROBLEM: Trailing comma after last array item caused JavaScript syntax error
ROOT CAUSE: PHP foreach loop always added comma after each object:
{...},
{...}, // <-- trailing comma before ]
];
While modern JS allows trailing commas, some parsers or contexts
(like when injected/evaluated) don't handle it well.
SOLUTION: Only add comma between items, not after last item:
1. Count total items before loop
2. Track current index in loop
3. Add comma only if currentIndex < itemCount
GENERATED JS NOW:
[
{...},
{...},
{...} // <-- no trailing comma
]
This eliminates the syntax error.