Encountering issues while retrieving date data from Firebase in Angular 6


this.qS = this.afDatabase.list('path', ref => {
    return ref.limitToLast(1000);
  }).snapshotChanges().map(changes => {
    return changes.map(c => ({ key1: c.payload.key,value1:c.payload.val() }));
  });
  this.qS.subscribe(values => {
    let count: number = Object.keys((values)).length;
    for(let i=0;i<count;i++){
           let const2:number=Object.keys(values[i].value1).length;  // is 3
           for(let j=0;j<const2;j++){
              console.log( values[i].value1[j]);//this line gives undefined why and How to get value from this?
            }
    }
  });

values[i].value1 =>[object Object]

JSON.stringify(values[i].value1)=>
    {"-LJ2PhylTGjo1Li6QxP4":{"dtime":{"befor_":0,"dates":"04-Aug-2018","from_t":14,"fullDetails":"Between 2 PM to 6 PM on 7-08-2018","id":1,"mDay":"7","mMonth":"08","mYear":"2018","to_t":18,"weak":2},"lan":0,"lon":0},"-LJ2PtF3X9OaH-5Lv982":{"dtime":{"befor_":0,"dates":"04-Aug-2018","from_t":14,"fullDetails":"Between 2 PM to 6 PM on 7-08-2018","id":1,"mDay":"7","mMonth":"08","mYear":"2018","to_t":18,"weak":2},"lan":0,"lon":0},"-LJIQjbtU7Ryz-gUcxRF":{"dtime":{"befor_":0,"dates":"07-Aug-2018","from_t":14,"fullDetails":"Between 2 PM to 6 PM on 8-08-2018","id":1,"mDay":"8","mMonth":"08","mYear":"2018","timestampCreated":{"timestamp":1533629365655},"to_t":18,"weak":3},"lan":0,"lon":0}}

Now we need to read fullDetails date from above string . How to do it in typescript ?

Answer №1

Utilize the for in loop when dealing with Objects:

for (var index in values[i].value1) {
    console.log(values[i].value1[index].dtime.fullDetails)
} 

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

The number of columns does not align with the number of values in the first row in Angular 8

Currently, I am in the process of adding a new Vendor to my database by sending a POST request through my Angular App. Here is the code snippet from vendor.service.ts: addVendor(data) { return this.http.post<any>(this.apiUrl + `vendormanagemen ...

Use Javascript to extract an array of strings enclosed in double quotes

Is there a way to extract an array containing ["13139","13141", "13140"] from the following data structure? { "13139": [tx[0]], "13141": [tx[1]], "13140": [tx[2]] } I attempted to use JS ...

The image hover feature is not functioning as expected in Angular 4

Currently, I am involved in a project using Angular 4. One particular section involves changing images on hover. Although I have implemented the following code, it does not seem to be functioning correctly for me. Interestingly, the same code works perfect ...

What causes JSON parsing errors with encoded characters in node.js?

I'm currently trying to search for the definition of the word "flower" using Google's dictionary semi-API. Here is the source I am referencing: You can find more information at this link In short, I am making a JSONP call with a callback parame ...

When using TypeScript, the tls.TLSSocket() function may trigger an error mentioning the absence of a "socket" parameter

Currently, I am in the process of building a basic IRC bot and using raw sockets to connect to the IRC server. Initially written in plain Javascript, I am now transitioning it to TypeScript. However, I have encountered an unusual issue when attempting to c ...

Guide to sending a post request with a file and JSON data in Node.JS using the request module

I've successfully implemented this code in Python for a specific problem, but I'm facing some challenges while trying to execute it in Node.JS using the request module. This is my Python code : inputData = { "datasetName": "dataset44", "typ ...

Preparing a JSON Array for an API Integration

Currently working on designing RESTful API endpoints that require GET/POST (fetch/add) functionality for an array of objects. Is there a significant advantage to using this format: {"Objects" : [{"Field1:Val1","Field2:Val2"},{"Field1:Val1","Field2:Va ...

What are the steps for adding an audio file to Firebase Storage?

I'm currently attempting to upload an audio file to Firebase Storage within my Ionic2 project. Initially, I successfully recorded the audio file using the Media plugin (Cordova plugin), and it is playing back correctly from both Android storage and t ...

Posting JSON data to a WebApi Controller in Objective-C

I'm working on implementing a javascript function that sends data to an ASP.NET Web Api controller. Here's the code snippet: var d = { NorthEastPoint: { Latitude: boundingBox.ne.lat, Londitude: boundingBox.ne.lng }, S ...

Looking for CakePHP error views for handling JSON and XML responses?

I am currently in the process of developing a REST API using CakePHP. Essentially, when I send requests to endpoints like add.json, the input data is processed and a JSON response is returned. Similarly, if I send it to add.xml, an XML response is generate ...

Modify certain parameters in the current route using Angular 6 router

Within my Angular 6 setup, the URLs are structured as follows: /{language}/{app_section}/{object_id}/{view}?queryparams... All sections of the application utilize a language selector component, which is included in the template of a parent route to ensur ...

Redux - a method of updating state through actions

Hello, I am currently working on developing a lottery system and I have a question regarding the best approach to modify state using action payloads. Let's consider the initial state: type initialCartState = { productsFromPreviousSession: Product[ ...

Having trouble with the Spotify API showing Error 400 "Invalid JSON Format" in Python?

Hey there! I've been working on a small project in my free time that involves integrating the Spotify API. Everything was going smoothly until I encountered an issue with a specific endpoint on the Spotify API. The problematic endpoint is (you can c ...

Issue with Material UI Table not refreshing correctly after new data is added

Currently, I am utilizing a Material-UI table to display information fetched from an API. There's a form available for adding new entries; however, the problem arises when a new entry is added - the table fails to update or re-render accordingly. For ...

How to pass a JSON object to a component's constructor in Angular 2

In a unique situation, my primary component config.editor.component performs extensive processing and generates various JSON objects. I am content with this approach. The template for this component then proceeds to render another component - api.entry.com ...

Utilizing Async and await for transferring data between components

I currently have 2 components and 1 service file. The **Component** is where I need the response to be displayed. My goal is to call a function from the Master component in Component 1 and receive the response back in the Master component. My concern lies ...

Preflight CORS error 403, yet my header is correctly set

Currently developing an Ionic app that communicates with an API on a web server for database operations. A similar project was completed in the past, and I copied the code from there, but it's not functioning as expected. Below are the headers config ...

I'm encountering a status 415 error when trying to post to the Spotify API for tokens. Is there something I'm

My approach to interfacing with their API for the Authorization Code Flow is as follows: class func obtainAuthTokenPackage(authCode: String) throws { //Initiate a request var request = URLRequest(url: Gimme.theSpotify.urlFor(endpoint: .requestingT ...

Merge two JSON files into a single document

I am currently working on a script that is able to access a JSON file by using the code: $.getJSON( 'alfred.json', function(data) { ... } Recently, I have obtained a second file named alfred_offline.json, which follows the same structure a ...

The automatic inference of function argument types and the implementation of conditional types

I'm facing a specific scenario: There's a function that takes in a boolean and returns either a RealItem or an ImaginaryItem. I'm using conditional types to determine the return type based on the boolean argument. type RealItem = { color: s ...