Complete JS newbie here!
I made an Array with a few numbers in it. I added a function that will show me the lowest number. My question can I show the index of the lowest number?(even If I would change the numbers)
Here is my code in case you need it:
function func()
{
var low= 0;
var numbersArr=[29, 26, 44, 80, 12, 15, 40];
for(var i = 0; i <= numbersArr.length;i++)
{
if(numbersArr[i]< numbersArr[i-1])
{
low = numbersArr[i];
}
}
console.log(low);
}
func();
const lowestNumber = numbers.map(n => n).sort()[0];. Assortmutates, I first create a new array so that the original one is not mutated.Math.min.applyto find min value. No need to write function. and then useindexOfto find the index. Check the below answer.