Try to search your question here, if you can't find : Ask Any Question Now ?

Loop into an empty array with javascript get query

HomeCategory: stackoverflowLoop into an empty array with javascript get query
Avatarwillson asked 5 months ago

I want to push the results which I get from mysql into an empty array (totalJuice)

var sqlgetgauge = 
"SELECT juice1_num FROM `customers_out` WHERE MONTH(date)=4 ";

   connection.query(sqlgetgauge, function(err, results, field) {
        if (err) throw err;


        for (i = 0; i < results.length; i++) {


            var numberjuice1 = Number(results[i].juice1_num / 100);

            var totalJuice = [];

            totalJuice.push(numberjuice1);
            console.log(totalJuice);

            //This is a Gauge Update
            juice_num_1.update({
                value: numberjuice1,
            });

        }


    });

but this code keep showing me result by console.log(totalJuice);

gauge_picker.js:85 [0.5]
gauge_picker.js:85 [0.02]
gauge_picker.js:85 [0.02]

I expect array will be [0.5 ,0.02 , 0.02 ]

and additional question is how I get a total of this array?

1 Answers
Best Answer
AvatarAmit answered 5 months ago
Your Answer

11 + 0 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com