G
G
Galdar Turin2021-02-15 18:17:02
Node.js
Galdar Turin, 2021-02-15 18:17:02

How to implement iteration with remembering indexes?

I have already encountered this but not in practice, I can’t find a solution to this problem simply because I can’t correctly form a search query, the bottom line is that when iterating over values ​​and executing a query to the database, the function itself remembers only the last index

spoiler
for( var i in list )
    {

        connect.query( `SELECT * FROM \`${list[ i ]}\``, ( error, result ) => {

            if( error )
            {
                console.log( error );
            }
            else
            {
                
                object[ list[ i ] ] = object[ list[ i ] ] || {};
                object[ list[ i ] ] = result;
                
            }

        })

    }

thus, only the last key from the array is written to object, a link to the solution will be more than enough
Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question