Can someone please explain how to display a specific element from a JSON Array?

Is there a way to display only this specific part?

/db/User_DataDb/61500546-4e63-42fd-9d54-b92d0f7b9be1 from the entirety of this

Object obj.sel_an:

[
    {
        "__zone_symbol__state":true,
        "__zone_symbol__value":"/db/User_DataDb/61500546-4e63-42fd-9d54-b92d0f7b9be1"
    }
]

My code snippet is as follows:

console.log("obj.sel_an: ",
JSON.stringify(this.sel_and.__zone_symbol__value))

Upon execution, I encounter an error in the console: ‘obj.sel_an: undefined.

https://i.sstatic.net/y0Z13.png

Answer №1

Hello @Misaz, I wanted to share my response that was mentioned in the previous comment.

Below is a snippet of code from my project:

db.Coll1.find()
         .equal('id', and.id)
.resultList(result => {
                result.forEach(db1 => {
                  if (db1.sel_and === null) {
                     db1.sel_and = new Set();                                                                
                }

               if (db1.sel_an === null) {
                    db1.sel_an = new Array();
               }


 db1.sel_an.push(promise1); // this adds promise1 to JsonArray 
 db1.sel_and.add(promise1);  // this adds promise1 to a Set()



   var db_child: any;
   db_child = db1.sel_and.forEach(function (child) {console.log(child[0].__zone_symbol__value) });
   console.log(" db1.sel_and: ", db_child);
    return db1.update({ refresh: true });
    });

The output represented by JsonArray looks like this:

  1. The value added using db1.sel_an.push(promise1);
    saved in the collection as:

    [ { "__zone_symbol__state": true, "__zone_symbol__value": "/db/User_DataDb/f6fe3fe3-17f1-49d8-83c3-b36dda42026d" } ]

Console output:

ZoneAwarePromise {__zone_symbol__state: null, __zone_symbol__value: Array(0)}
  __zone_symbol__state:true
  __zone_symbol__value:"/db/User_DataDb/d79ef084-17fc-441c-a8eb-13ba0a14f083"
  __proto__:Object
  1. This is the extracted result from Set()

-> “db1.sel_and.add(promise1);” -> it appears as [null] in the Collection, but the expected outcome should be -> ["/db/User_DataDb/f55bf96d-2cb9-467f-8aa8-d60aced32fcf"]

Set(1) {ZoneAwarePromise {__zone_symbol__state: true, __zone_symbol__value: "/db/User_DataDb/f55bf96d-2cb9-467f-8aa8-d60aced32fcf"}}
  size:(...)
  __persistedSize__:1
  __persistedState__:Object
  __proto__:Set
  [[Entries]]:Array(1)
  0:null
  length:1

3.    

db_child = db1.sel_and.forEach(function (child) { console.log(child[0].__zone_symbol__value) });
     console.log(" db1.sel_and: ", db_child);

I attempted to access child[0].__zone_symbol__value but encountered errors:

Uncaught (in promise): TypeError: Cannot read property '__zone_symbol__value' of undefined
TypeError: Cannot read property '__zone_symbol__value' of undefined
    at http://localhost:3000/main.bundle.js:28348:116
    at Set.forEach (native)
    at http://localhost:3000/main.bundle.js:28348:69
    at Array.forEach (native)
    at http://localhost:3000/main.bundle.js:28336:44
    at ZoneDelegate.invoke (http://localhost:3000/polyfills.dll.js:4341:26)
    at Object.onInvoke (http://localhost:3000/vendor.dll.js:30326:37)
    at ZoneDelegate.invoke (http://localhost:3000/polyfills.dll.js:4340:32)
    at Zone.run (http://localhost:3000/polyfills.dll.js:4133:43)
    at http://localhost:3000/polyfills.dll.js:4720:57
    at ZoneDelegate.invokeTask (http://localhost:3000/polyfills.dll.js:4374:31)
    at Object.onInvokeTask (http://localhost:3000/vendor.dll.js:30317:37)
    at ZoneDelegate.invokeTask (http://localhost:3000/polyfills.dll.js:4373:36)
    at Zone.runTask (http://localhost:3000/polyfills.dll.js:4173:47)
    at drainMicroTaskQueue (http://localhost:3000/polyfills.dll.js:4553:35) 
    at ZoneTask.invoke (http://localhost:3000/polyfills.dll.js:4431:25)

If I exclude [0] from child, I get “undefined”. If I use child.__zone_symbol__value, I get incorrect information. How can I avoid the usage of “[0].__zone_symbol__value” without encountering an error? Is there a way to achieve this?

Thank you.

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

Arranging two arrays: What's the best way to organize the numbers in my arrays

Given two arrays: int array1 [] = {1,2,3,4,5,6,7}; [The size of this array can increase significantly] int array2 [] = {1,2,3}; [Can contain a maximum of 30 elements] In this scenario, array1 is intended to be the parent loop and will have more elements ...

Tips for integrating Excel files with NestJS

I'm in the process of developing a REST API that will utilize a third-party API to retrieve specific status information. The URLs needed for this API are stored in an Excel file, which is a requirement for this use case. My goal is to extract the URLs ...

Adjusting characteristics in Angular dynamically through JSON

Having trouble changing the value of [icon]="reactAtom" to use a JSON value? Need assistance in updating the [icon] value based on the 'featureItem' received from the parent component. HTML <div> <fa-icon [icon]="reactAtom" class="i ...

C incompatibility error with return value types

Two structs are defined as follows: #define M 100 #define N 100 typedef struct xml_Element { pData_Element data; pAttr_Element attr_arr[M]; struct xml_Element *parent; struct xml_Element *children[N]; int depth; int num_of_childre ...

The disappearing act of embedded Twitter timelines in Ionic 2

My code displays the timeline initially, but it disappears when I navigate away from the view. Can anyone help me troubleshoot this issue? Upon first visit to the view, the timeline is visible, but upon returning, it disappears. Below is the code snippet ...

Why am I getting the "Cannot locate control by name" error in my Angular 9 application?

Currently, I am developing a "Tasks" application using Angular 9 and PHP. I encountered a Error: Cannot find control with name: <control name> issue while attempting to pre-fill the update form with existing data. Here is how the form is structured: ...

Whenever the return condition is false, make sure to subscribe to the Angular CanActivate Guard

In my UserAccessGuard class, I have a method that captures the current path and compares it to the user's available paths. However, I am facing asynchronous problems because the condition inside the subscribe block causes my Hasaccess variable to rema ...

The attribute "property" is not found in the specified type of "Request<ParamsDictionary>"

Struggling to enhance the Request interface in the express package with custom properties, I keep encountering this TypeScript error: TS2339: Property '' does not exist on type 'Request<ParamsDictionary>'. Any ideas on how to re ...

Tips for transferring data to an entry component in Angular 2 using ng-bootstrap modal

I've been grappling with sending data to a custom modal content component in Angular 2. My objective is to have the flexibility of calling this modal from any other component without duplicating code. Despite my efforts, including referencing the "Com ...

Why am I receiving a peculiar type error with @types/jsonwebtoken version 7.2.1?

My current setup includes node v6.10.3, typescript v2.3.4, and jsonwebtoken v7.4.1. Everything was running smoothly until I decided to upgrade from @types/jsonwebtoken v7.2.0 to @types/jsonwebtoken v7.2.1. However, after this update, an error started poppi ...

What is the best way to alter a specific value within an object without losing other important data?

I'm currently working on developing a function that will activate when the count either matches or is half the initial price required to open, and it should not reset to false even if the count drops back to 0. Below is some sample data: openData = { ...

What is the best way to transform a nested dictionary containing numpy arrays into JSON and vice versa?

I have recently entered the world of Python and I am facing a challenge with converting a nested dictionary that contains NumPy arrays into JSON format. My goal is to convert it to JSON and then back to the original nested dictionary with NumPy arrays. W ...

Retrieve the radio button value without using a key when submitting a form in JSON

Looking to extract the value upon form submission in Angular, here is the code: In my Typescript: constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController, public formBuilder: FormBuilder, public alertCtrl ...

If a condition is met by an element in the array, then move that element to the first position

Within my PHP code, there exists a multi-dimensional associative array: $myArray = array( 'a' => array('foo'=>'one', 'bar'=>'two'), 'b' => array('foo'=>'three&ap ...

Minimize the cyclomatic complexity of a TypeScript function

I have a typescript function that needs to be refactored to reduce the cyclometric complexity. I am considering implementing an inverted if statement as a solution, but it doesn't seem to make much of a difference. updateSort(s: Sort) { if (s.ac ...

Retrieving information from the Dog API using axios and storing the results in a fresh array

Currently, I am working on a NextJS app using Typescript. My issue lies in the functionality aspect of the application. I am utilizing the Dog API to retrieve all the breeds names and store them in a new array of arrays. Each sub-array contains the breed a ...

Is Angular 2 Really Suitable for Multi-Page Applications?

I am currently working on a multi-page app using Angular2 and have noticed that the load times are slower than desired when in development mode. While searching for solutions, I came across a thread on stackoverflow that explains how to set up Angular2 fo ...

Skip creating declarations for certain files

src/ user.ts department.ts In the scenario outlined above, where there are two files in the src directory (user.ts and department.ts), is there a way to exclude the generation of declaration files specifically for department.ts when running tsc wi ...

Issue with Angular ngFor within a particular dialog window?

(respPIN and internalNotes are both of type InternalNotes[]) When the code in encounter.component.ts is set like this: this.ps.GetInternalNotes(resp.PersonID.toString()).subscribe(respPIN => { this.internalNotes = respPIN; }); An ERROR occurs: Err ...

Transform an array into an object with assigned key names

How can we transform the following array: [2019,2020,2021] into the format: { 0: {year:2019}, 1: {year:2020}, 2: {year:2021} } ...