Top community members
All Wiki Articles Create Wiki Article

Have you ever heard about encyclopedia for code?

What about: Wiki for Code project?

* because I've tried to share code and my solutions on different services and it was removed or I was unwelcomed
   - maybe it wasn't good place, but this one is.

if you think you have solution that can help someone, you are welcome to share this solution - Click here

TypeScript - array map method example

0 contributions
4 points

In TypeScript it is posslbe to map array in following way.

1. Array map method example

This section shows how to make example conversion of array items. 

let inputArray = [
    {
        id : 1,
        name : 'John',
        email : 'john@gmail.com',
        password : 'john-password',
        age : 43
    },
    {
        id : 2,
        name : 'Kate',
        email : 'kate@gmail.com',
        password : 'kate-password',
        age : 54
    },
    {
        id : 3,
        name : 'Diego',
        email : 'diego@gmail.com',
        password : 'diego-password',
        age : 21
    },
];

let outputArray = inputArray.map((oldItem : any) : any =>
{
    let newItem = {
        name : oldItem.name,
        age : oldItem.age
    };
    
    return newItem;
});

console.log(outputArray);

Output:

[ 
  { name: 'John', age: 43 },
  { name: 'Kate', age: 54 },
  { name: 'Diego', age: 21 }
]

Note: Array.prototype.map method is usefull to simplyfy arrays.

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more