JSFiddle - React, Tailwind, and code Playground

by John Grivas

HTML

<input id="btnGo" value="Go" type="button" /> <span id="msg"></span>

<span id="msg">Check results in console</span>

JavaScript

$("#btnGo").click(function () {
                performUpdate();
            });

            function performUpdate() {

                var arr_promises = [];

                var students = [{
                    id: 1,
                    name: 'John',
                    scoresYear1: [{
                        subject: 'maths',
                        score: 8
                    }, {
                        subject: 'chemistry',
                        score: 7
                    }],
                    scoresYear2: [{
                        subject: 'maths',
                        score: 9
                    }, {
                        subject: 'chemistry',
                        score: 8
                    }]
                }, {
                    id: 2,
                    name: 'Mary',
                    scoresYear1: [{
                        subject: 'maths',
                        score: 9
                    }, {
                        subject: 'chemistry',
                        score: 8
                    }],
                    scoresYear2: [{
                        subject: 'maths',
                        score: 10
                    }, {
                        subject: 'chemistry',
                        score: 7
                    }]
                }];

                $.each(students, function (index, student) {

                    arr_promises.push(SaveStudent(student));


                });

                $.when.apply($, arr_promises).done(function () {
                    var total = arguments.length;

                    console.log('Total : ' + total);
                });
            };

            function SaveStudent(student) {

                executeQueryAsync(student,

                function () {
                    // Save scores year 1
                    $.each(student.scoresYear1, function (index, score) {
                        executeQueryAsync(score,

                        function () {
        ...