 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Find the shortest string in an array - JavaScript
We are required to write a JavaScript function that takes in an array of strings and returns the index of string that is shortest in length.
We will simply use a for loop and persist the index of string which is shortest in length.
Example
Following is the code −
const arr = ['this', 'can', 'be', 'some', 'random', 'sentence']; const findSmallest = arr => {    const creds = arr.reduce((acc, val, index) => {       let { ind, len } = acc;       if(val.length < len){          len = val.length;          ind = index;       };       return { ind, len };    }, {       ind: -1,       len: Infinity    });    return arr[creds['ind']]; }; console.log(findSmallest(arr));  Output
This will produce the following output in console −
be
Advertisements
 