Generating JSON data from a loop with refined outcomes

My goal is to iterate through JSON data and extract "time", "blocks" information, while filtering the "amounts" based on a specific variable named _miner.

So far, I've successfully retrieved the name, time, and blocks data, but I'm struggling with properly filtering the final amounts for a specific addr. Once this is done, I plan to display the results in a table to present them to the user.

[
   {
      "name":"zelcash",
      "pending":{
         "blocks":[

         ],
         "confirms":{

         }
      },
      "payments":[
         {
            "time":1531601680340,
            "txid":"de12e0a3a0d75df7f9d5da6e78896ec5f6d72c0063df8d059b90d66a6aa0d535",
            "shares":3386.04739737,
            "paid":149.85034477,
            "miners":2,
            "blocks":[
               119148
            ],
            "amounts":{
               "t1XHpNtYY2N3EMDRoX9RM2hq4DWWPZSmawJ":94.69254759,
               "t1ZsrJASHjvSU8mcLA4K1KuBYESMpXQgwpM":55.15779718
            },
            "balances":{

            },
            "work":{
               "t1XHpNtYY2N3EMDRoX9RM2hq4DWWPZSmawJ":2139.69113513,
               "t1ZsrJASHjvSU8mcLA4K1KuBYESMpXQgwpM":1246.35626224
            }
         },
         // More payment entries...
      ]
   }
]

Ajax/JS

$.ajax({
    url: "https://xxxxxx/api/payments",
    dataType: 'json',
    success: function (data) {

        var _miner = "t1XHpNtYY2N3EMDRoX9RM2hq4DWWPZSmawJ";

        var addr = _miner;

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

            console.log(data[i].name);

                var payments = data[i].payments;
                for (var j = 0; j < payments.length; j++) {

                    var blocks = payments[j].blocks;
                    for (var b = 0; b < blocks.length; b++) {
                        //console.log(blocks[b])
                    }

                    console.log(payments[j].amounts);


                }
            }

    },

    error: function() {
        //alert("Was unable to get info!");
    }
});

I want the console output to look like this so I can later format it into a table:

zelcash
1531601680340
94.69254759
zelcash
1531599760228
94.33175716
//repeat

Answer №1

Your explanation is not clear. I believe it might be the solution you are looking for. Please review and confirm.

    for (let x = 0; x < info.length; x++) {
        let transactions = info[x].transactions;
        for (let y = 0; y < transactions.length; y++) {
          //Sender
          console.log(info[x].sender);

          //Timestamp
          console.log(transactions[y].timestamp);

          // Values
          if (transactions[y].values[_customer] !== 'undefined')
            console.log(transactions[y].values[_customer])
        }
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using AJAX with C# to implement an AutoCompleteExtender with a specific context key

Is there a way to dynamically pass parameter/control to contextKey? <asp:TextBox ID="tbA" runat="server" autocomplete="off"></asp:TextBox> <asp:TextBox ID="tbB" runat="server">hello</asp:TextBox> <asp:TextBox ID="tbC" runat="s ...

JQuery: Issue with Passing Value in a Select Query

I am having trouble passing the selected value from a drop-down list to a select query on another page. Although the drop-down boxes are populated successfully, they do not filter the comments by topic ID as expected. My goal is to pass the chosen value fr ...

Using JQuery to enhance the functionality of ajax-loaded content

Having difficulty implementing a more/less functionality in an ajax-loaded section of a webpage. I customized a script found at http://jsfiddle.net/gDvyR/72/, primarily by adding "on" functionality to address the ajax issue. You can view the modified ver ...

The slides on SlickJS are initially loaded in a vertical alignment, but once the arrows are interacted with,

I've put together a demonstration that highlights the issue I'm facing. Upon visiting the contact section, you'll notice that all the slickJS slides are stacked vertically initially, but once you interact with them by clicking on the arrow o ...

I am looking for a way to connect a saved phone number with a Vue tel input so that I can make changes

Currently, I am utilizing vue-tel-input to input a phone number. Below is the code snippet: <template> <div> <vue-tel-input v-model="client.ClientPhone" v-bind="bindPropsUserInfo"></vue-tel-input> </div> ...

JQuery is unable to validate a form that is being loaded from an external HTML file

I'm encountering an issue where my form imported into a separate HTML file is not validating using JQuery's $(form).validate() plugin. After following the guidance provided in this question, I successfully managed to get the form working. Howeve ...

Condition in Angular Schema Form

I'm currently utilizing Angular Schema Form to dynamically generate a form based on JSON Schema. My goal is to display the email textfield only when the user inputs the string "abc", however, the email field does not appear after entering "abc". I sus ...

Perform the cloning process for each item listed in my JSON file

I'm trying to display a list of names from a JSON file on my webpage, each in their own separate div. However, I've been unsuccessful in getting it to work so far. Currently, this is what I have attempted: var cloneTeam = $('.team').c ...

Decoding JSON in an Android mobile application

I'm a beginner with android and I have a `JSON` object. How can I parse my `JSONArray`? [ { "Men":, "shirts": [ { "name":"ABC", "image":"http://domain.com/image.jpg" }, ...

Ways to access an element in a Java ArrayList with two dimensions?

I recently converted a JSON string into a Java ArrayList and now I'm trying to retrieve a specific element from it. However, using .get(0).get(2) as an example doesn't seem to provide the desired result, as I discovered in another query. Upon u ...

Please provide links to both the image and text within a Rails 3.1 application

Hey there! I have a small piece of code and I'm wondering how to add a link to both the icon and text. I am calling an icon from a class. Check out my code below: <td class="cv-class_<%= index + 1 %>"> <a onClick="ad ...

An AngularJS-powered dynamic navbar

Apologies if my explanation is unclear, but I am struggling to find a simple way to convey the following information. I have set up a navigation bar that displays different categories of articles. These navigation items are pulled from a database and can ...

Rapidly process likes from all Facebook friends by making multiple JSON requests

I had an interesting idea to develop a program that could analyze the likes of a person's Facebook friends. While there are likely other applications out there claiming to find your "Perfect Match" based on this data, I wanted to create something uniq ...

Using Ajax to Continuously Check for Updates on User Notifications

Looking for a server-side language solution that can send notifications to users based on new MySQL row additions. I have a subscription system in place, so my idea is as follows: Whenever a new row is added to the posts table, the server side language w ...

I am wondering about the proper method for deleting multiple records simultaneously in Ember Data

My current challenge involves managing a list of record IDs, such as [1, 20, 20]. The process of individually querying and deleting each item is proving to be quite inefficient. store.findRecord('post', 1).then(function(post) { post.deleteRec ...

How to Extract YouTube Audio URL on an iPhone

I have been working on a JavaScript code that can fetch the direct download URL for videos from the mobile YouTube website. [webView stringByEvaluatingJavaScriptFromString:@"function getURL() {var player = document.getElementById('player'); var ...

Only one class is allowed to access the API value

Recently, I created some classes (JsonData which consists of getters and setters for the Json value retrieved from an API): GetSetJsonData: class GetSetJsonData { HttpClient client; #region SuccesLogin JsonData.SuccesLogin.RootObject succesL ...

Converting the AppDelegate.m file to AppDelegate.mm and updating the AppDelegate.h file during the transition from React Native 0.66.4 to 0.71.3

Original code in AppDelegate.h: #import <React/RCTBridgeDelegate.h> #import <UIKit/UIKit.h> #import <UserNotifications/UserNotifications.h> @interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificat ...

The Vue application is encountering an unexpected error in Chrome that is puzzling me as I search for a solution

Currently, I am delving deep into learning Vue.js and have decided to revisit the documentation from scratch and work through it in reverse order. Below is the content of my index.html file: <!DOCTYPE html> <html lang="en"> <hea ...