How to Access an Array and its elements?
The easiest way to access an array is by using its Index. In the above example, the first element can be accessed as a[0], second with a[1], and so on. The index starts from 0 and ends with length(array)-1. Let’s look at the below example, where we have 2 elements in the array and we are accessing the values by their index.
@echo off set a[0]=5 set a[1]=12 echo The first element of the array created is %a[0]% echo The second element of the array created is %a[1]%
The Above code will produce the following output.
The first element of the array created is 5 The second element of the array created is 12
Batch Script – Arrays
An array is a collection of elements of the same data type. The arrays are not explicitly defined as Batch Script types but can be used. The following items need to be noted when the same members are used in Batch Script.
- Each aspect of the same members needs to be defined by a set order.
- A ‘for’ loop will be required to double the program values.
Contact Us