6 September 2024

The JSHint error "Expected an identifier and instead saw ']'. (E030)" usually occurs when there is a syntax issue in your JavaScript code involving square brackets ([]). The least obvious is that you have to use .push() function to add to the array.

Source code viewer
  1. const children = [];
  2.  
  3. // Adding an object with a key and value using push (works).
  4. children.push({
  5. key: 'uniqueKey',
  6. value: 'someValue'
  7. });
  8.  
  9. // Attempting to add an object without specifying the index (Does NOT work!).
  10. children[] = {
  11. key: 'uniqueKey',
  12. value: 'someValue'
  13. };
  14.  
  15. console.log(children);
  16. // Output: [{ key: 'uniqueKey', value: 'someValue' }]
Programming Language: Javascript