Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7039645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:49:25+00:00 2026-05-28T01:49:25+00:00

var idd; $.each(data, function (i, items) { //1st each $.each(items, function (j, item) {

  • 0

var idd;

$.each(data, function (i, items) { //1st each
    $.each(items, function (j, item) { // 2nd each
        console.log("Field:" + j + " Value:" + item);

        if (j=="sha_id"){ idd=item; }

    });
    console.log("Items");
    console.log("ID:" + idd);

    db.transaction(function (tx) {
        console.log("being inserted");
        console.log("ID Inserting:" + idd);
        //then some database insertion query

This is sample upper part script

Basically 1st .each will run 2 round and 2nd .each will run two round for each 1st .each

So in console log I expect to see
field …. value
field ….. value
Items
ID : 2
being inserted
ID Inserting : 2
field …. value
field ….. value
Items
ID : 3
being inserted
ID Inserting : 3

But what i am getting is this

field …. value
field ….. value
Items
ID : 2
field …. value
field ….. value
Items
ID : 3
being inserted
ID Inserting : 3
being inserted
ID Inserting : 3

Why my db.transaction is not executed just after console.log(“Items”) at first as they are in the same loop. Is there any code error i should correct ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:49:26+00:00Added an answer on May 28, 2026 at 1:49 am

    Presumably db.transaction is asynchronous.

    This means the $.each loops continue to run, and don’t wait for db.transaction to complete.

    When db.transaction is finally complete, the callback you gave it is invoked. This happens (relatively) long after the $.each loops have finished.

    The moral of the story is that any code that should wait for the db.transaction to complete, must be invoked within the db.transaction callback you’re passing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var results = ['one', 'two', 'one hundred', 'three']; var removal = []; $.each(results, function(i)
var data = { message: Posting SWF using FB.api, display: 'iframe', caption: Caption Field,
var y = new w(); var x = y.z; y.z= function() { doOneThing(); x();
var thumbs = document.getElementsByTagName(img); for (var i=0; i<thumbs.length; i++) { Core.addEventListener(thumbs[i], click, function() {alert(i);});
var myOptions_bench = { 1 : '1', 2 : '2', 3 : '3'} $.each(myOptions_bench,
<script type=text/javascript> var num=2; function addElement() { var ni = document.getElementById('myDiv'); var newdiv =
var imageData = context.getImageData(0, 0, canvas.width, canvas.height); var data = imageData.data; and var data
var UsersMenu = function(){ this.returnUsers = []; this.retrieve = function(posts){ var temp = [];
var allRapidSpells = $$('input[value^=RSW]'); Can anyone tell me what that does?
var plugin = { Init: function() { this.UpdateUI(); if (this.Status() == 1) { ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.