Regardless the the language, you will occasionally encounter an error message that the table of contents exceeds the border of the array, that is, table of contents was exterior the border of the array(the offered index of variety exceeds the actual table of contents of the array). For example, over there are just 5 aspects in an array, and also the index (subscript) of variety starts native 0. If the variety is characterized as a, and the worth of a<5> is take away in this way, an out-of-bounds error the the range will it is in reported because the index of the last facet is 4, and also the last element should it is in a<4>.

Of course, together low-level failure are seldom made in the actual advance process. They are usually dynamic arrays produced by routine operation, and index was external the bounds of the range due come some scenarios that space not considered for the time being. Then ns will provide some instances of typical indexes past the bounds of the array. In order come meet various needs, I will give examples of languages such together javascript and also C#.

I. Javascript selection index the end of bounds

Example 1: The indexof variety starts indigenous 1, the password is as follows:

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


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


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

Example 2: The length of array is not judged, and the arbitrary worth causes range index the end of bounds

If you want to acquire all the div tag of webpage, without judging how many divs there space in advance, just use the subscript to get the value, the code is as follows:

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

If there is no div or just one in the webpage, arr<1> will certainly cause variety out of limit 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

See more: How Do You Force A Kenmore 80 Series Washer Won T Drain Or Spin

Table of contents was external the limit of the array in C#

If you desire to get all text papers in a folder, if you use the length of variety to obtain the critical element, one error which index was outside the bounds of the selection will occur. The password is as follows:

/// /// C# obtain all text records in a folder/// /// Folder path private void GetTxtFiles(string path){DirectoryInfo di = brand-new DirectoryInfo(path);FileInfo<> arrFi = di.GetFiles("*.txt");

//Errorstring temp = arrFi.Name;//Get the last facet with the size of array, the index of selection will be out of bounds