0

In typescript, I need to convert an array class and feed it to other source. Kindly help to achieve the following in elegant way.

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"},]

Expected results after converting

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

Can you suggest me the best way to do it. Thanks in Advance.

1
  • .map() with Object.values(). Commented Mar 10, 2020 at 14:52

1 Answer 1

2

You can use array.map() along with object destructuring:

let input = [{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 = input.map(({Name,Age,Resource}) => [Name,Age,Resource]);
console.log(result);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.