Batch Script - How to Modifying an Array Last Updated : 04 Jan, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: We are creating an array with name 'array'.By using 'set' we are creating an array, by specifying the index of every element.set arr[0]=Geeks set arr[1]=for set arr[2]=GeeksNow we will add an element at the end of 'array' by using last index of array.In above code our last index will be '3'. So we will use below expression.set arr[3]=GFGAbove command will add 'GFG' at the end of array 'arr'.At last we are printing last element of array by using '%arr[3]%' , which will print 'GFG' as output as it is last element of our array now. 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: Now we are creating an array 'arr'.We want to replace 'and' by 'for' . So now we will use below expression to replace 'and' with 'for'.set arr[1]=forWe are using index of 'and' in given array for replacing it by 'for'.Then we are printing element at index 1, just to check whether its replaced or not.At last 'pause' is used to hold the screen, so that we can see our output. Output : Replacing element of any array Comment More infoAdvertise with us Next Article Batch Script - Arrays T thenavneet Follow Improve Article Tags : Linux-Unix Batch-script Similar Reads Batch Script - Length of an Array The length of the array is the number of elements in the array. The index of the array starts from "0" to "N-1" where N is a number of elements. For example arr[0]=1 arr[1]=2 arr[2]=3 Here we can see that the index starts from 0 and ends with 2 . So, we know that the index of the element goes from 0 2 min read Batch Script - Iterating Over an Array A batch script is a set of instructions or a script for SOS and Windows Operating System. We can write them in the CMD line by line or we can create a file with a ".bat" or ".cmd" extension. The file can contain valid instructions for executing by the interpreter. The meaning of batch is the non-int 3 min read 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â loo 5 min read Batch Script - Creating Structures in Arrays In this article, we'll understand how to create structures in arrays in a batch script. What are Structures? Structures are like a multi-type list of values, unlike arrays we have a list of single type values. Let's say we have an array called person, we have initially declared to a list of names, b 2 min read How to Insert a New Element in an Array in PHP ? In PHP, an array is a type of data structure that allows us to store similar types of data under a single variable. The array is helpful to create a list of elements of similar types, which can be accessed using their index or key.We can insert an element or item in an array using the below function 5 min read Array Basics in Shell Scripting | Set 1 Consider a situation if we want to store 1000 numbers and perform operations on them. If we use a simple variable concept then we have to create 1000 variables and perform operations on them. But it is difficult to handle a large number of variables. So, it is good to store the same type of values i 6 min read Like