Asynchronously solution to check data from database kinds of loop clause
<p>What I want to do is asynchronously check from database and get a result from it? In my application I am trying to implement <code>Asynchronously</code> to resolve this steps as</p>

<ol>
<li>Check mobile numbers from database as <code>JsonArray</code> kinds of loop clause </li>
<li>Create <code>JsonArray</code> from Result</li>
<li>Print created array </li>
</ol>

<p>I learned just enough about <code>Promises</code> to write the following connection, but then unfortunately my solution could't be implemented <code>Asynchronously</code> and I get multi row as result on the console.</p>

<p><strong>1)</strong> First step is to pass data as json array to check mobile numbers from the database</p>

<pre><code>registeredUsers(data)
    .then(function (value) {
        console.log('Contents: ' + value);
    }).catch(function (v) {
    console.log("faile");
});
</code></pre>

<p><strong>2)</strong> After that I have two function inside <code>Promise</code></p>

<pre><code>function registeredUsers(data) {
    return new Promise(function (resolve, reject) {
        var accountNumbers = [];
        for (var i = 0; i &lt; data.length; i++) {
            var mobileNumber = data[i].mobileNumber.substr(1, data[i].mobileNumber.length);
            checkUserMobileNumberAsEwallet(mobileNumber).then(function (mobileNumber) {
                accountNumbers.push({ewalletNumber: mobileNumber});
            }).catch(function (v) {
                reject(false)
            });
        }
        console.log(accountNumbers);
        resolve(accountNumbers);
    });
}

function checkUserMobileNumberAsEwallet(mobileNumber) {
    return new Promise(function (resolve, reject) {
        var query = "SELECT id FROM userEwallets WHERE ewalletNumber LIKE '%" + mobileNumber + "'";
        connection.query(query, function (err, results) {
            if (err) return reject(false);

            if (results.length &gt; 0)
                resolve(mobileNumber);
        });
    });
}
</code></pre>

<p>What is my code problem? Why I can't implementing this?</p>