Stopping a variable from running as a funtction in Javascript

Viewed 26

I have a service accessing a MYSQL database, but the value returned by the server is stored as result.COUNT(*) (I'm counting the entries in a table), when I try to use this result, it seems to try and execute a function with the parameter *.

     console.log(result[0].COUNT(*));
                                  ^

SyntaxError: Unexpected token '*'
1 Answers

If you use bracket notation it should work, e.g.:

console.log(result[0]['COUNT(*)']);

You can also provide an alias in your SQL query, e.g.

"SELECT COUNT(*) as UserCount FROM Users"

then

console.log(result[0].UserCount);
Related