Open In App

Batch Script – How to Modifying an Array

In this article, we are going to learn how we can modify any array using Batch Script.

We can modify any array in two ways. We can add elements in any array or we can replace elements of any array.



Modify an array by adding an element.

Code :



@echo off 
set arr[0]=Geeks
set arr[1]=for
set arr[2]=Geeks
::adding an element at the end of array.
set arr[3]=GFG
echo The last element of the array is %arr[3]%
pause

Explanation:

set arr[0]=Geeks
set arr[1]=for
set arr[2]=Geeks
set arr[3]=GFG

Output:

Output of above code

Modify an array by replacing its Element :

Code :

@echo off 
set arr[0]=Geeks
set arr[1]=and
set arr[2]=Geeks
::replacing an element in any array.
set arr[1]=for
echo The new element at 1 index is %arr[1]%
pause

Explanation:

set arr[1]=for

Output :

Replacing element of any array

Article Tags :