Array Objects

Arrays topic in TypeScript is divided into following parts:

Array Objects

We can use Array object to create arrays. We can use Array constructor to pass array values. We can pass values in two ways:
– If we pass a numeric value to the constructor, it represents the size of the array
– Multiple values separated by comma represents the elements of the array
Syntax

var arrayName:dataType = new Array();

Below is an example, where we declare an Array object, assign values to it and then retrieve those values. You can use for loop as well to assign value to array.

var num:number[] = new Array(3);
var i:number;
num[0] = 10;
num[1] = 20;
num[2] = 30;
for(i=0;i<num.length;i++){
    console.log(num[i]);
}

Below is the output of above code

Let’s pass element values to Array Constructor.
Below is an example

var num:number[] = new Array(10,20,30);
var i:number;
for(i=0;i<num.length;i++){
    console.log(num[i]);
}

Below is the output of above code

Power Platform Academy

Start or Upgrade your Career with Power Platform

Learn with Akanksha

Python | Azure | AI/ML | OpenAI | MLOps

Design a site like this with WordPress.com
Get started