JSFiddle - React, Tailwind, and code Playground

by sathish panduga p

JavaScript

var dataset = {
    "d0": { "id": 0, "name": "Housing", "value": 18 },
    "d1": { "id": 1, "name": "Travel", "value": 31.08 }
};




// Declare resulting empty array
var d = [];

// Get object keys and iterate over them
Object.keys(dataset).forEach(function (key) {
    // Get the value from the object
    var value = dataset[key].value;

    // Update values if in the range
    if(value >= 10 && value <= 20) {
        dataset[key].value = 7;
    } else if(value > 20 && value <= 40) {
        dataset[key].value = 8;
    }

    // Push the updated(or not) value in the array
    d.push(dataset[key]);
});

alert(JSON.stringify(d, null, 4));