JS is a client side technology and does not have the ability to access the database without the use of ArcGIS and a rest endpoint. If you publish the table to ArcGIS Server then you will be able to access it from JS API and do a record count query.
thank you for your answer.it's helpful for me.thanks again!
Don't forget to mark this question as answered by clicking on the "Correct Answer" link on the reply that answered your question.
The way I have done this in the past is to include the SDE table inside the MXD of another layer you need to publish. The standalone table will now be published as a layer inside the service that you can query using queryTask, etc.
Retrieving data ...