Finding the minimum value of a nested object property
Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
-
Marius
- Posts: 106
Finding the minimum value of a nested object property
I have a nested object in JavaScript that looks like this:
Code: Select all
const yo = {
one: {
value: 0,
mission: 17},
two: {
value: 18,
mission: 3},
three: {
value: -2,
mission: 4},
}
I want to find the minimum value of the 'mission' property within the nested objects.
How can I do that in a simple way?
Admin
Try combine the
Object.values() and
map() methods, like in the following example:
Code: Select all
const yo = {
one: {
value: 9,
mission: 17
},
two: {
value: 18,
mission: 6
},
three: {
value: 3,
mission: 4
},
}
const val_mission = Object.values(yo).map(({ mission }) => mission);
let min_mission = Math.min(...val_mission);
console.log(min_mission); // 4
Similar Topics
-
How to change key in JS object
JavaScript - jQuery - Ajax
First post
I have a question: i want to change keys into a JavaScript object if their value is number, for example, I have the following object:
const...
Last post
To change a key into a JavaScript object, you need to clone the value with the new key, and then you delete the old key in the object.
const...
-
Invert key value in js object
JavaScript - jQuery - Ajax
First post
I can't figure out how I can change the following object in JavaScript:
{ first : , second : , third : }
to:
{ de : , ab : }
I want to...
Last post
You have to loop the array and for each item in the array check if an array for that value exists in the accumulator or not before adding it:...
-
Get the length of a JSON object in JS
JavaScript - jQuery - Ajax
First post
I have converted a database table into a JSON object.
This is in essence a two-dimensional array, with each record being the first dimension, which...
Last post
You can use Object.keys to get the list of keys in the Object as an array and then get the length from it:
Object.keys(act_obj_array).length;
-
Random object from multiple arrays with percent chance in JS
JavaScript - jQuery - Ajax
First post
I have 3 arrays of objects in JavaScript:
const fruits =
const car =
const books =
One temporary array where I will store random objects...
Last post
You need to get two random numbers:
- the first to decide which group to pick,
- the second to pick an item from that.
We generate a random...