

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript Array showing the index of the lowest number
We are required to write a JavaScript function that takes in an array of numbers. Then the function should return the index of the smallest number in the array.
Example
The code for this will be −
const arr = [3, 56, 56, 23, 7, 76, -2, 345, 45, 76, 3]; const lowestIndex = arr => { const creds = arr.reduce((acc, val, ind) => { let { num, index } = acc; if(val < num){ num = val; index = ind; }; return { num, index }; }, { num: Infinity, index: -1 }); return creds.index; }; console.log(lowestIndex(arr));
Output
The output in the console −
6
- Related Questions & Answers
- Return the lowest index in the string where substring is found using Python index()
- Highest and lowest value difference of array JavaScript
- Finding the index position of an array inside an array JavaScript
- Highest and lowest in an array JavaScript
- Return the lowest index in the string where substring is found in a range using Python index()
- Returning the first number that equals its index in an array using JavaScript
- Get the index of the nth item of a type in a JavaScript array
- Sorting digits of all the number of array - JavaScript
- Pair of (adjacent) elements of an array whose sum is lowest JavaScript
- Find the next lowest number higher than a certain number in MySQL?
- Find closest index of array in JavaScript
- Finding median index of array in JavaScript
- Finding the index of the first element that violates the series (first non-consecutive number) in JavaScript
- For each element return the lowest index in the string where substring is found in Python
- How can I find the index of a 2d array of objects in JavaScript?
Advertisements