Smallest number in array and its position

arrays, javascript

Solution

Just loop through the array and look for the lowest number:

var index = 0;
var value = temp[0];
for (var i = 1; i < temp.length; i++) {
  if (temp[i] < value) {
    value = temp[i];
    index = i;
  }
}

Now `value` contains the lowest value, and `index` contains the lowest index where there is such a value in the array.

Problem

What I am trying to achieve is to find smallest number in array and its initial position. Here's an example what it should do: ``` temp = new Array(); temp[0] = 43; temp[1] = 3; temp[2] = 23; ``` So in the end I should know number 3 and position 1. I also had a look here: Obtain smallest value from array in Javascript?, but this way does not give me a number position in the array. Any tips, or code snippets are appreciated.

Original source

Related problems