Converting Array Class into an Array of Arrays using Typescript

Looking to convert an array class in typescript and pass it to another source. Seeking help on achieving this task in a clean and efficient manner.

data : target[] = [{Name : "XXX", Age : "31",DOB : "20-12-1988", Resource: "Java"},
{Name : "YYY", Age : "21",DOB : "20-12-1998", Resource: "Dot Net"},
{Name : "ZZZ", Age : "31",DOB : "1-12-1988", Resource: "SQL"},
{Name : "AAA", Age : "26",DOB : "20-12-1988", Resource: "Angular"},
{Name : "BBB", Age : "28",DOB : "20-12-1988", Resource: "React"},]

Desired output after conversion:

[["XXX","31","Java"],["YYY","21","Dot Net"],["ZZZ","31","SQL"],["AAA","26","Angular"],["BBB","28","React"]]

Any suggestions on the most effective approach would be greatly appreciated. Thank you in advance.

Answer №1

To achieve this, you can utilize the array.map() function in combination with object destructuring:

let data = [{Name : "XXX", Age : "31",DOB : "20-12-1988", Resource: "Java"},
{Name : "YYY", Age : "21",DOB : "20-12-1998", Resource: "Dot Net"},
{Name : "ZZZ", Age : "31",DOB : "1-12-1988", Resource: "SQL"},
{Name : "AAA", Age : "26",DOB : "20-12-1988", Resource: "Angular"},
{Name : "BBB", Age : "28",DOB : "20-12-1988", Resource: "React"}];

let result = data.map(({Name,Age,Resource}) => [Name,Age,Resource]);
console.log(result);

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

Navigating through various resources in AJAX content

I'm currently exploring possible solutions for resolving relatively referenced resources in dynamically loaded content. For instance, let's say I have this page downloaded from /index.html: <html><body> <div id="insert-here" /> ...

Trouble with JavaScript loading in HTML webpage

<!DOCTYPE html> <html> <head> <title>Breakout Game</title> <link rel="stylesheet" href="css/style.css"> </head> <body> <canvas width="900" height="450" class="canvas"></canvas> ...

Troubleshooting Tips for Node.js and MongoDB Socket Closure Issue

I'm running into an issue while working on the login system for my NodeJS application. Everytime I attempt to retrieve a collection, MongoDB throws me this unusual error. The Error Message [MongoError: server localhost:27017 sockets closed] name: &a ...

Is it possible to transfer a variable from my javascript code to a jsp file?

Within a HTML file, I have created a variable in JavaScript consisting of an array with two entries - a latitude and a longitude. I am looking to use AJAX to send this variable and then utilize it in my JSP file to populate a form. Does anyone have any su ...

Struggling to understand how to authorize Spotify in a React application

My goal is for a user to click a button on my React page, be redirected to Spotify to authorize, return to my page, and for my app to receive an access token. After reading through Spotify's authorization documentation, I realized that I need to impl ...

Why isn't the document.getElementById().value() function functioning properly within my PHP code?

When working on my PHP code, I included the following: <select class="ht__select" onchange="sorting('<?php echo $id ?>')" id="sorting"> <option value="">Default sorting</option> <option value="low_price">Sor ...

Position the buttons in the react children's application

**Looking for help on positioning Black Widow in the center-left and Hulk at the bottom left of the screen. I'm having trouble figuring it out, does anyone have any tips? Also, I only want to isolate the buttons to each picture. Not sure if I need to ...

Browsing across pages seamlessly without the need to refresh the browser

I need help with making my admin panel built using Bootstrap and integrated with Laravel navigate through tabs without refreshing the browser. Can anyone provide guidance on how to modify the code to achieve this functionality? You can check out the admin ...

Is there a way to exclusively use ES6 to import jQuery from an npm package?

After installing jQuery using npm -install jquery, a node_modules folder was created in my project with the jQuery library inside. However, I encountered an error when trying to import it using ES6 import. I am looking for a solution that does not involve ...

What is the reason behind this Uncaught TypeError that is happening?

After converting my questionnaire to a PHP file and adding a validation script, I encountered an error: Uncaught TypeError: Cannot set property 'onClick' of null The error is pointing me to line 163 in my JavaScript file, where the function f ...

Error: Unable to locate module: "./library". The parent module directory is "/"

I keep encountering an issue in my project when attempting to load a module. Whenever I try to import it from the node_modules folder, I receive the following error: Uncaught Error: Module not found: "./MyLibrary". Parent module folder was: "/" However, i ...

Oops! There was an error: Uncaught promise rejection: TypeError - Unable to access 'subscribe' property of null object (Ionic Angular)

I encountered an issue in my angular ionic project. When I log in, the first page displays the error "ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'subscribe' of null." However, upon reloading the page, the error disappears ...

What causes the React Query cache to be cleared upon page reload?

Hi there, I am new to Next.js and React Query. I would really appreciate any help or advice. I apologize for any mistakes in my English language skills. Currently, I am using Next.js v12 and React Query v3, along with the React Query DevTools. On one of ...

combining multiple applications on a single page using AngularJS

I am currently developing an application using AngularJS. Within my application, I have implemented two controllers to manage two distinct views. Below is the JavaScript code: var myApp1 = angular.module('myApp1', []); myApp1.controller(' ...

Discovering the presence of a component in Angular 1.5

Link to embedded content $injector.has('myMessageDirective') is returning true, while $injector.has('myMessageComponent') is not. Has anyone else encountered this issue or found a solution? I am concerned that my components may not be ...

Unable to see Bootstrap 5.2 Modals in action with documentation demo

Here is an example that I copied and pasted from the documentation on https://getbootstrap.com/docs/5.2/components/modal/: <!-- Button trigger modal --> <button type="button" class="btn btn-primary" data-bs-toggle="modal&q ...

Ways to activate ajax calls using a JavaScript chart

Newbie in the world of Javascript. I have a forced directed graph from spring.js and I am trying to trigger ajax from it when a user selects a node. However, I keep encountering an error: Uncaught SyntaxError: Unexpected token . The issue seems to be cente ...

Creating an anchor element with text and a bootstrap icon involves using the appropriate HTML structure and

I am trying to figure out how to create an element that includes both text and a Bootstrap icon. Here is the HTML code: <a> Edit <i class="icon-pencil" /> </a> Can anyone help me understand how to select this DOM element using jQuer ...

A helpful guide on performing a service call in AngularJs when attempting to close the browser tab or window

I am currently working on implementing a service call that will trigger when the browser tab or window is being closed. I was wondering if there is a way to make a RestApi call when attempting to close the browser tab or window. Does anyone have any sugge ...

Using HTML and JavaScript, we can set two different color values - one for the background and one for the h1 title

I am trying to save two values, one for the h1 tag and one for the body background. I want the user to select color 1 and color 2. When I press the third button, all changes should be applied and the colors should change. I have attempted this but with no ...