When using translate.get with an array of strings in Angular 5, the function will return both the keys and values, not just

Currently, I am utilizing Angular 5 to manage internationalization through ngx-translate within my code.

To elaborate on the issue at hand, I have a data table that pulls information from a web service and displays it correctly. There is also a button that allows users to export the data to a CSV file using Angular5csv. The function below retrieves the headers for the CSV file based on the selected language:


    getHeader(){
      this.translateService.get(['app.lblInvSupNum','app.lblInvTANum',
                                 'app.lblDateInv'  ,'app.lblDueDate',
                                 'app.lblAmount'  ,'app.lblCurrency',
                                 'app.lblStatut'  ,'app.lblBlockCode',                              
                                ])
                            .subscribe((res: any[]) =>{
                              this.header=res;
                              console.log(this.header);
                            })  
  

Upon displaying the results in the console, the output looks like this:

{app.lblInvSupNum: "Supplier Invoice Number", app.lblInvTANum: "Invoice Number", app.lblDateInv: "Invoice date", app.lblDueDate: "Due Date", app.lblAmount: "Amount", …}

My goal is to create an array of strings to pass to angular5csv. A desired format would be:

[
    'Supplier Invoice Number', 
    'Invoice Number', 
    'Invoice Date', 
    'Due Date', 
    'Amount', 
    'Currency', 
    'Status', 
    'Blockage Code'
  ]
  

Thank you in advance for any assistance provided.

Answer №1

To achieve this, simply employ the Object.keys method in combination with .map, as illustrated below:

let outcome = Object.keys(this.data).map((item) => this.data[item])

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

Retrieve the name from the accordion that was clicked

Hey there, I have a simple accordion that is based on an API called "names". <div *ngFor="let item of showDirNames | async | filter: name; let i = index;"> <button class="accordion" (click)="toggleAccordian($event, i)&q ...

pytrends_json.decoder.JSONDecodeError: Anticipating a value at line 1, column 1 (character 0)

When I execute this code, I encounter an error: from pytrends.request import TrendReq google_username = '' google_password = '' pytrend = TrendReq(google_username, google_password, custom_useragent='My Pytrends Script') pytre ...

When utilizing Javascript's Array.push method, a nested array is generated that is inaccessible using the index

I have reviewed several articles discussing the issue of asynchronous calls returning undefined. Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference Get data from fs.readFile However, none of these articles ...

Tips for sending a parent property as a reference rather than a value to a child component using an @Input decorator

When a parent component passes a property to a child component using the @Input decorator in Angular 2, it is passed by value and not by reference. If there is a need to change the parent's property within the child component, the new value must be em ...

Is there a way to generate the specific JSON file format using my PHP script?

Here is the desired output: [ {"Airtel":{"v": 50.00}}, {"Hutch":{"v": 10.00}}, {"Idea":{"v": 10.00}}, {"TATA":{"v": 10.00}}, {"Vodafone":{"v": 20.00}}, {"Aircel":{"v": 15.00}} ] Since the data is retrieved from a MySQL database, it ...

Using ajax and json to create interconnected dropdown menus

I'm currently working on implementing a dependent drop-down field in PHP. Everything seems to be functioning correctly, as it displays the printed array values. However, the JSON returned value does not seem to populate the second drop-down list. Can ...

Creating a custom inner class in JAVA to handle complex JSON data involves defining a class within

I have gone through many posts but I can't seem to find a solution on how to create a class for this JSON. { "snippet": { "parentGroupId": "69ea5920-0157-1000-0000-0000028e1b90", "processors": {}, "processGroups": { ...

Troubleshooting image loading issues when updating the base URL in an Angular JS project

I am trying to update the base URL for my application. Currently, when I load the application, the URL shows up as http://localhost:4200/#/, but I want it to be http://localhost:4200/carrom/ instead. To accomplish this, I modified the base URL and now th ...

Angular 2 Demonstrate Concealing and Revealing an Element

I am currently facing an issue with toggling the visibility of an element based on a boolean variable in Angular 2. Below is the code snippet for showing and hiding the div: <div *ngIf="edited==true" class="alert alert-success alert-dismissible fade i ...

Manipulate JSON data in PHP using arrays

I need some help with accessing a value from my JSON Array. Here is the PHP code I am using to retrieve the JSON content: $input = @file_get_contents("php://input"); $event_json = json_decode($input); $event = \Stripe\Event::retrieve($event_id); ...

Ways to resolve the Ionic v1 deprecation error problem

I am facing a problem with an Ionic v1 deprecation error, causing it to not work properly. ionic build ios ionic emulate android The basic commands are failing to produce the desired outcome. Is there a way to resolve this issue? Note: My application is ...

What is the best way to showcase a half star rating in my custom angular star rating example?

component.ts import { Component } from '@angular/core'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { projectRating ...

Make sure to confirm that 'tables-basic' is an Angular component within the module before proceeding

In my table-basic.component.ts file, I declared 'tables-basic' as a selector and included this template in dashboard.html. Despite following the steps outlined below, I encountered an error which is also highlighted. Snippet from my dashboard.te ...

Issues with decoding JSON data in PHP

Struggling to assign a JSON Object to a PHP Variable? When attempting to use var_dump, it's showing NULL. Here is the PHP code: <?php $json = utf8_encode(file_get_contents('http://socialclub.rockstargames.com/ajax/stat/1/profile_body/sta1/ ...

Having trouble with nativescript-pager after updating nativescript-cli to version 6.0?

Error Found:- ERROR TypeError: Could not load view for: Pager.TypeError: Unable to access property 'PagerAdapter' of null ERROR TypeError: TNSViewPager is not a constructor Sample Code Snippet:- <Pager row="0" [items]="itemList" [selecte ...

Step-by-step guide on crafting a harmonious row of a label and a responsive button group

One of my projects involves a form that contains a list of elements. I want this form to be responsive and suitable for all screen sizes. When I initially run the project on a larger screen, everything looks good. However, when I resize the screen to a sma ...

What is the process for deserializing a JSON-wrapped collection property into a generic class

The Challenge Many APIs that return RESTful JSON data wrap collections within an object. This object typically includes a property indicating the number of items in the collection. Consider the following examples: { "animals": [ {"name": "Ra ...

Replacement of JSON keys with Play2

In Play2, is it possible to replace a key with another in the received JSON object? Here's an example of changing the JSON: { "name" : "My name" } We can modify it to be: { "nameAndSurname" : "My name" } What if my JSON is more complex? Can I sti ...

Issue with Fullcalendar's events.php causing JSON object retrieval failure

I'm attempting to send a JSON object as a response to my fullcalendar ajax request, but instead of returning the desired result, it only returns an array. Although I am relatively new to JSON and PHP, I have conducted extensive research and have yet t ...

Troubles encountered while parsing nested JSON objects with a streaming parser

I'm currently using the code provided in this helpful resource for parsing my JSON: Although it successfully handles most of the JSON data I have, it encounters issues when a JSON object is directly nested as a child within another one. To illustrat ...