

- 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
Finding the smallest value in a JSON object in JavaScript
We are required to write a JavaScript function that takes in a JSON object as one and only argument.
The JSON object has string keys mapped to some numbers. Our function should traverse through the object, find and return the smallest value from the object.
Example
The code for this will be −
const obj = { "a": 4, "b": 2, "c": 5, "d": 1, "e": 3 }; const findSmallestValue = obj => { const smallest = Object.keys(obj).reduce((acc, val) => { return Math.min(acc, obj[val]); }, Infinity); return smallest; } console.log(findSmallestValue(obj));
Output
And the output in the console will be −
1
- Related Questions & Answers
- Finding the smallest multiple in JavaScript
- Finding the smallest fitting number in JavaScript
- Finding the smallest good base in JavaScript
- JavaScript Recursion finding the smallest number?
- Finding second smallest word in a string - JavaScript
- Sorting a JSON object in JavaScript
- Flattening a JSON object in JavaScript
- Finding smallest number using recursion in JavaScript
- Check whether a value exists in JSON object?
- Finding the length of a JavaScript object
- JSON group object in JavaScript
- Constructing a nested JSON object in JavaScript
- Get value for key from nested JSON object in JavaScript
- How to modify an array value of a JSON object in JavaScript?
- Finding difference of greatest and the smallest digit in a number - JavaScript
Advertisements