How to modify the elements of an array?
We can add a new element or modify the value of an existing element by using its index. The output of the below program is ‘last element is 12’
@echo off set a[0]=5 set a[1]=7 set a[2]=9 Rem Adding a new element at the array end Set a[3]=12 echo The last element is %a[3]%
Now let us look at modifying the existing value. In the below snippet, we assign a[2] as 14 and the third element of the array is now 14
Set a[2]=14
echo The new value of the third element of the array is %a[2]%
The output of the above snippet results in the below behavior
The new value of the third element of the array is 14
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