Learn Creating and printing array in TypeScript in these quick 2 mins tutorials
In this tutorial, we will learn to create an array using TypeScript. After creating an array, we will be printing the array. If you’re not aware of how to create a variable in TypeScript, you can follow the link mentioned below. It is mandatory to learn the basic initially before learning to create an array.
Once you have learnt to create essential variables and print them. You’ll be learning how to create an array. Creating an array is similar to creating a variable. The following coding will depict how to create an array variable and pass values to them.
Open our demo.ts file and clear any existing code which we tried in the last tutorial. Now to create an array, you can use the following code. We are creating an array of employees data.
let enq_List = [
{name:"John", id:123, dept:"IT"},
{name:"Victor", id:124, dept:"Finance"},
{name:"Doe", id:125, dept:"HR"}
]
To print the array, we need to call the array name inside the console log.
console.log(enq_List)
After the console coding, you can follow the same step and convert the file to js and then run the file.
tsc demo.ts
node demo.js
The output is as follows.
{name:"John", id:123, dept:"IT"}
{name:"Victor", id:124, dept:"Finance"}
{name:"Doe", id:125, dept:"HR"}
Now that you have learnt Creating and printing array in TypeScript. In the next tutorials, we will learn how to access a particular member in an array. Angular with Angular Material Training from Ampersand Academy
Leave a Reply