Tips for showing a nested array in Ionic 3

I am trying to showcase the array of array data.

This is how my API has responded:

{
  "product_id": "13",
  "is_master": "0",
  "sku": "Variable_product_15",
  "upc": "",
  "price": "40.00000",
  "pricing_calculator": "standard",
  "shipping": "0",
  "params": "{\"variant_main_image\":\"images\\/themeparrot\\/clothing_products_06.png\"}",
  "length": "0.00000",
  "width": "0.00000",
  "height": "0.00000",
}

Within this array, I specifically want to display the variant_main_image.

This is how my ts file looks like:

variableprod() {
  let j2s = this.vproductsj2sid.find(x => x.j2store_variant_id === this.vprodid);
  console.log("display"+JSON.stringify(j2s));
  this.vcategorydata = JSON.parse(JSON.stringify(j2s.price));
  console.log(JSON.stringify("vname: "+JSON.stringify(this.vcategorydata)));
  this.vpdimages = JSON.parse(JSON.stringify(j2s.params));
  this.vimg = this.vpdimages.variant_main_image; 
  console.log(JSON.stringify("vimg: "+JSON.stringify(this.vimg)));
}

However, in the log output, it only says "vimg: undefined"

Answer №1

this.dataImages = JSON.parse(j2s.inputs);

Utilize JSON.parse() exclusively instead of

this.dataImages = JSON.parse(JSON.stringify(j2s.inputs));

Answer №2

Give this a shot!

const apiResponse = {
  "product_id": "13",
  "is_master": "0",
  "sku": "Variable_product_15",
  "upc": "",
  "price": "40.00000",
  "pricing_calculator": "standard",
  "shipping": "0",
  "params": "{\"variant_main_image\":\"images\\/themeparrot\\/clothing_products_06.png\"}",
  "length": "0.00000",
  "width": "0.00000",
  "height": "0.00000",
};

const receivedData = JSON.parse(apiResponse);
console.log(receivedData.variant_main_image)

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

Discovering the technique to unearth a specific value within an array nested within another array

I am encountering an issue with finding a value in one array inside another array and utilizing the resulting value to update the state using setState(). Here is the initial state: this.state = { initialStudents:[ {name:"str1",tags;["str","s ...

Explore the titles provided by Wikipedia

Hi there, I'm fairly new to Angular and trying to work with the Wikipedia API. However, I seem to be having trouble getting 4 titles from the API. Here's an example URL for one of the titles: https://en.wikipedia.org/w/api.php?action=query&pr ...

Empty Angular-chart.js Container

How can I resolve the issue of getting a blank div and no output while trying to display a chart where the options, labels, and other data are initialized in the TypeScript controller and then used on the HTML page? I added the angular-chart.js library us ...

Converting a custom object into a params-object in Typescript/Angular 12

I am seeking to utilize the fromObject property of HttpParamsOptions in order to convert a custom object into a params-object. Here is an example where it works: foo(): void { const testObject = { id: 123; name: 'test'; someExa ...

The persistence of Ionic Native Storage seems to be lost upon app rebuilding

After using ionic 3 native storage to store a value with the line of code below: this.storage.set('myValue', this.value); I proceeded to rebuild the app and tried to retrieve that value, but it came back as null: this.storage.get('myValue ...

Unable to execute cURL function

I am currently attempting to send bulk text messages through a website using an API. I have set up the $sendString variable with the specific URL for the API, but for some reason, the cURL function is not working properly with this particular URL. To trou ...

Issue reported: "Usage of variable 'someVar' before assignment" ; however, it is being properly assigned before usage

This piece of code showcases the issue: let someVar: number; const someFunc = async () => { someVar = 1; } await someFunc(); if (someVar == 1) { console.log('It is 1'); } As a result, you will encounter ...

Tips for developing a personalized form validator for validating JSON data exclusively in Angular

Within my Angular application, there exists a reactive form that has a single control known as configJson, which is visually represented by a <textarea> element in the DOM. The primary goal is to validate this specific form control to ensure that it ...

Substitute values smaller than a certain threshold with zeros in a NumPy array

In my Python script, I am working with a NxT Numpy array that contains N time series data points (random walk) of length T. My goal is to identify any values in a specific series (row) that are below a certain threshold, let's say 8000, and replace th ...

PrestoDB - Fetching rows based on the presence of varchar column in an array query

I have a dataset that looks like this: WITH data AS ( SELECT * FROM ( VALUES (1, "foo"]), (2, "bar") ) AS t (ID, Column1)) SELECT ID, Column1 FROM data Now I want to apply ...

Unexpected error while trying to parse a NumPy array using PyArg_ParseTuple function

I developed a basic Python extension method in C to handle Numpy arrays, but unfortunately, it crashes when executed. static PyObject *test(PyObject *self, PyObject *args) { PyArrayObject *array = NULL; if (!PyArg_ParseTuple(args, "O!", &PyAr ...

Issue encountered when using createReducer/handleAction in Redux along with TypeScript and typesafe-actions: Invalid argument provided for Argument 1

I tried following the guide on typesafe-actions in order to set up a basic TypeScript/Redux project, but I'm encountering issues. Whenever I attempt to access the page, I keep getting this error message, Error: Argument 1 is invalid, it should be an ...

Refreshing the View in Ionic and AngularJS Using Controller UpdatesIn this tutorial, we will

As a newcomer to both Ionic and Angularjs, I am currently in the process of developing a simple Ionic app. The main functionality involves displaying a list of classes (sessions), allowing users to book or cancel a class by clicking on an icon, and updatin ...

An easy way to insert a horizontal line between your text

Currently, I have two text responses from my backend and I'm considering how to format them as shown in the design below. Is it possible to automatically add a horizontal line to separate the texts if there are two or more broadcasts instead of displa ...

How to use attributes in Angular 2 when initializing a class constructor

Is there a way to transfer attributes from a parent component to the constructor of their child components in Angular 2? The process is halfway solved, with attributes being successfully passed to the view. /client/app.ts import {Component, View, bootst ...

"Exciting developments in Angular 17 with the introduction of the new @

I need to output elements from an array of strings starting at index 1. arr = [ "str1", "str2", "str3", "str4", "str5" ] The desired output is: str2 str3 str4 str5 To achieve this, use a new @for loop in ...

What is the most effective way to determine the data type of a value associated with a key in an interface?

In my TypeScript interface, I have defined the following structure: MyInterface { 'key1': number | string; 'key2': string; 'key3': SomeOtherInterface; } I am looking to create a new type that utilizes the properties of ...

Issue with Angular and OIDC - user data is missing upon logging in

I am in the process of developing an application using Angular along with IdentityServer as the Single Sign-On (SSO) provider in ASP.NET. After successfully logging in and retrieving user information from the authentication server: User info The followin ...

Initiating a GET request to execute an SQL query with specified parameters

Let me provide some background information. I am currently using Angular for the frontend and Express for the backend, while also learning how to effectively utilize both technologies. In my application, there is a parent component that generates a group ...

Developing applications with TypeScript in combination with Express()

My goal is to integrate the latest version of Express with node.js using TypeScript. However, I have encountered an issue with the express.d.ts file provided by Microsoft in the samples. It seems to be based on versions prior to 3.0.x. In older versions, y ...