I have a Array. I dont know how large the array is. How can I get index of the smallest number in the array?
I know array contains only numbers.

If you can modify the arrangement of the numbers in the array and the numbers are 1 digit the solution is simple… [AS]myArray = [5, 3, 2, 6, 9]; //array with numbers
myArray.sort(); //sort array in numerical order
trace(myArray); //returns 2,3,5,6,9
trace(myArray[0]); //returns 2, the lowest number[/AS]

Otherwise, not too sure, I will see if I can cook something up.

Ok, well I got both busy and lazy, so a quick search at layer51 returns this…

Dont know if its the best code but it works:

my_array = [13, 3, 5, 8, 15, 4, 27];
Array.prototype.minValue = function() {
        var min = Number(this[0]);
        for (var i = 0; i<this.length; i++) {
                var temp = Number(this*);
                min = temp < min ? temp : min;
        return (min);
trace(my_array.minValue()); //outputs 3

Thank you claudio,
I edited your script a little and now it works like i need.

Welcome :slight_smile: