Square Brackets Notation

Using square brackets notation is the most common and straightforward method to declare an array of strings in TypeScript. It involves enclosing the string type within square brackets.

Syntax:

let myArray: string[] = ["string1", "string2", "string3"];

Example: In this example, we declare an array named fruits containing three strings representing different types of fruits.

Javascript




let fruits: string[] = ["Apple", "Banana", "Orange"];
console.log(fruits);


Output

["Apple", "Banana", "Orange"]

How to Declare an Array of Strings in TypeScript ?

Arrays are fundamental data structures in TypeScript, enabling developers to manage collections of elements efficiently.

Below are the approaches to declare an Array of strings in TypeScript:

Table of Content

  • Square Brackets Notation
  • Array Constructor

Similar Reads

Square Brackets Notation

Using square brackets notation is the most common and straightforward method to declare an array of strings in TypeScript. It involves enclosing the string type within square brackets....

Array Constructor

...

Contact Us