I want to run Sql Query in script how can i do this

You can use ES6 Promise inside for-each function. So that the loop stop, wait for response from ajax call, than continue loop again with response data.
Promises are a clean way to implement async programming in JavaScript (ES6 new feature). Prior to promises, Callbacks were used to implement async programming. Let’s begin by understanding what async programming is and its implementation, using Callbacks.