Regardless of the language, you will periodically encounter one error post that the table of contents exceeds the border of the array, the is, index was external the border of the array(the supplied index of selection exceeds the actual index of the array). Because that example, over there are just 5 elements in an array, and also the table of contents (subscript) of array starts from 0. If the array is identified as a, and also the worth of a<5> is bring away in this way, one out-of-bounds error the the variety will be reported since the table of contents of the last element is 4, and the last facet should it is in a<4>.

Of course, such low-level mistakes are seldom made in the actual breakthrough process. They are usually dynamic arrays generated by regime operation, and also index was exterior the bounds of the selection due come some situations that room not taken into consideration for the time being. Then ns will provide some examples of usual indexes beyond the bounds of the array. In order to meet various needs, I will certainly give instances of languages such as javascript and C#.

I. Javascript array index out of bounds

Example 1: The indexof selection starts indigenous 1, the code is together follows:

var arr = <1, 2, 3, 4, 5, 6>;


for(var i = 1; i var tmp = arr;//When i = arr.length, the index of variety is the end of bounds}


for(var ns = 0; i var tmp = arr;}

Example 2: The size of array is not judged, and also the arbitrary worth causes array index out of bounds

If you desire to get all the div sign of webpage, there is no judging how many divs there space in advance, simply use the subscript to obtain the value, the code is as follows:

var arr = document.getElementsByTagName("div");var temp = arr<1>;

If over there is no div or only one in the webpage, arr<1> will cause an array out of border error. The exactly code should be judged through adding:

if(arr.length > 1)var temp = arr<1>;


You are watching: Index was outside the bounds of the array meaning

See more: Through Which One Of The Following Mediums Is The Velocity Of A Sound Wave The Greatest

Index was outside the bounds of the variety in C#

If you want to get all text papers in a folder, if you use the length of array to acquire the last element, an error which table of contents was exterior the bounds of the variety will occur. The code is together follows:

/// /// C# gain all text files in a folder/// /// Folder path personal void GetTxtFiles(string path){DirectoryInfo di = new DirectoryInfo(path);FileInfo<> arrFi = di.GetFiles("*.txt");

//Errorstring temp = arrFi.Name;//Get the last element with the size of array, the table of contents of variety will be the end of bounds