TypeScript

Easy 2 mins Tutorials in Creating and printing array in TypeScript

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. 

First program in TypeScript

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.

Creating and printing array in TypeScript
Creating and printing array in TypeScript

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

Dinesh Kumar R

Director at Mahadhi Technologies, Mahadhi Healthcare, Ampersand Academy, Motorjob, Swadata Analytics. I create engaging user interfaces for enterprise-level applications using HTML, CSS, SCSS, JavaScript, JQuery, TypeScript, Angular Material, Bootstrap, MaterializeCSS. I also craft beautiful, lead-generating websites which engages the visitors. Connect with me with your creative needs. Favourite Quote: If everything seems under control, you are just not going fast enough.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button