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));
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.