This is a sample code I'm trying to build. The actual JSON has a lot more data making the "switch" statement portion of the code not very practical to maintain (currently the only way I could make it work).
Is there a way to replace it by something similar to what I used for the other data "Model1" & "Model2" to make use of dynamic data used in the "for" loop?
I created a test at: https://jsfiddle.net/ShaiHul/evrqj1b5/42/
var data = {
"Car": {
"wheels": 4,
"InStock": {
"Toyota": {
"Model1": 10,
"Model2": 5
},
"Honda": {
"Model1": 12,
"Model2": 3
}
}
},
"Bicycle": {
"wheels": 2,
"InStock": {
"Toyota": {
"Model1": 25,
"Model2": 14
},
"Honda": {
"Model1": 22,
"Model2": 13
}
}
}
};
var vehicles = [{
name: "Car"
},
{
name: "Bicycle"
}
];
for (i in vehicles) {
var vehicle = vehicles[i].name;
document.getElementsByClassName(vehicle + "Model1")[0].innerHTML = vehicle + ", Toyota, Model 1: " + data[vehicle].InStock.Toyota["Model1"];
document.getElementsByClassName(vehicle + "Model2")[0].innerHTML = vehicle + ", Toyota, Model 2: " + data[vehicle].InStock.Toyota["Model2"];
switch (vehicle) {
case "Car":
document.getElementsByClassName(vehicle + "Wheels")[0].innerHTML = vehicle + ", Toyota, Wheels: " + data.Car["wheels"];
break;
case "Bicycle":
document.getElementsByClassName(vehicle + "Wheels")[0].innerHTML = vehicle + ", Toyota, Wheels: " + data.Bicycle["wheels"];
break;
}
}
<div class="CarModel1"></div>
<div class="CarModel2"></div>
<div class="CarWheels"></div>
<br/>
<div class="BicycleModel1"></div>
<div class="BicycleModel2"></div>
<div class="BicycleWheels"></div>
You can use nested Object.entries() and loop through them like this to get any dynamic data at any position:
var data={"Car":{"wheels":4,"InStock":{"Toyota":{"Model1":10,"Model2":5},"Honda":{"Model1":12,"Model2":3}}},"Bicycle":{"wheels":2,"InStock":{"Toyota":{"Model1":25,"Model2":14},"Honda":{"Model1":22,"Model2":13}}}};
const $vehicles = document.getElementById("vehicles");
Object.entries(data).forEach(([key, value]) => {
Object.entries(value.InStock).forEach(([vehicleName, models]) => {
Object.entries(models).forEach(([modelName, count], index) => {
$vehicles.innerHTML += `<div>${key}, ${vehicleName}, Model ${index + 1}: ${count}</div>`
});
$vehicles.innerHTML += `<div>${key}, ${vehicleName}, Wheels: ${value.wheels}</div>`;
});
$vehicles.innerHTML += '<br>' // add a line between vehicle types
});
<div id="vehicles">
</div>
I'm using template literals to create the content of each div. You can create it using + on each string if it's not supported in your browser yet.
Like this:
$vehicles.innerHTML += '<div>' + key + ', ' + vehicleName + ', Model ' + (index + 1) + ':' + count + '</div>';
Here's the updated fiddle
Updated fiddle without using template literals
Sure thing! Your switch statement can go from this:
switch (vehicle) {
case "Car":
document.getElementsByClassName(vehicle + "Wheels")[0].innerHTML = vehicle + ", Toyota, Wheels: " + data.Car["wheels"];
break;
case "Bicycle":
document.getElementsByClassName(vehicle + "Wheels")[0].innerHTML = vehicle + ", Toyota, Wheels: " + data.Bicycle["wheels"];
break;
}
to this:
document.getElementsByClassName(vehicle + "Wheels")[0].innerHTML =
vehicle + ", Toyota, Wheels: " + data[vehicle]["wheels"];
The key part in this new form is the data[vehicle]["wheels"] section, at the very end. Instead of using known object properties Car and Wheel, just use the variable vehicle which should be set to the string Car or Bicycle, which are also the property names in the json data you have at the top of your question.
So your entire for-loop would just look like this in the end:
for (i in vehicles) {
var vehicle = vehicles[i].name;
document.getElementsByClassName(vehicle + "Model1")[0].innerHTML = vehicle + ", Toyota, Model 1: " + data[vehicle].InStock.Toyota["Model1"];
document.getElementsByClassName(vehicle + "Model2")[0].innerHTML = vehicle + ", Toyota, Model 2: " + data[vehicle].InStock.Toyota["Model2"];
// new line, replacing your switch statement
document.getElementsByClassName(vehicle + "Wheels")[0].innerHTML =
vehicle + ", Toyota, Wheels: " + data[vehicle]["wheels"];
}
Related
I have an exercise where from an object constructor, I have created several objects, all with an ID property.
The first part of the exercise consist in pairing each object, compare their markAv properties and print the one that had it bigger.
[ a vs b => b wins]
They suggested to do so by using the ID property but I didn't know how to do it that way... so I tried a workaround, as you will see in the code below.
However, the second part of the exercise wants me to do the same but, this time, creating the pairs randomly. Here I have tried to use the ID property by generating a random number that matches the ID but I don´t know how to structure the code for it to work.
The output for the second part should be the same as above, with the only difference that the pairing is now randomly generated.
I have added a partial solution for the second part, partial because from time to time it throws an error that I can´t identify. However, I think I'm getting close to get my desired output.
I would really appreciate if anyone could give me a hint for me to crack the code below and to get it working because I really want to understand how to do this.
class Avenger {
constructor(name, classRoom, city, job, studies, markAv, id) {
this.name = name;
this.classRoom = classRoom;
this.city = city;
this.job = job;
this.studies = studies;
this.markAv = markAv;
this.id = id;
}
heroList() {
return this.name + " " + this.classRoom + " " + this.city + " " + this.job + " " + this.studies + " " + this.markAv + " " + this.id
}
}
const tonyStark = new Avenger("Tony Stark", "XI", "NYC", "Ingeneer", "MIT", 10, 1)
const hulk = new Avenger("Hulk", "X", "Toledo", "Destroyer", "Scientific", 7, 2)
const daredevil = new Avenger("Daredevil", "IX", "NYC", "Lawyer", "Fighter", 2, 3)
const magneto = new Avenger("Magneto", "XXI", "SBD", "Unemployed", "Driver", 5, 4)
const unknown = new Avenger("Unknown", "L", "CDY", "President", "Clerck", 17, 5)
const xavi = new Avenger("Xavi", "XX", "BCN", "Analist", "Calle", 7, 6)
let heroes = [daredevil, hulk, tonyStark, magneto, unknown, xavi]
function getPairs(array) {
function getPairs(array) {
for (let i = 0; i < array.length; i += 2) {
if (array[i].markAv < array[i + 1].markAv) {
console.log(array[i].name + " vs " + array[i + 1].name + " " + array[i + 1].name + " Wins")
} else if (array[i].markAv > array[i + 1].markAv) {
console.log(array[i].name + " vs " + array[i + 1].name + " " + array[i].name + " Wins")
}
}
}
getPairs(heroes)
///
function randomAv(array) {
let result = []
let hero1 = heroes[Math.floor(Math.random() * 6) + 1]
for(let i = 0; i<array.length; i++){
if (array[i].markAv <= hero1.markAv && array[i].id != hero1.id) {
result.push(console.log(array[i].name + " vs " + hero1.name + " " + array[i].name + " Wins"))
} else if(array[i].markAv >= hero1.markAv && array[i].id != hero1.id) {
result.push(console.log(array[i].name + " vs " + hero1.name + " " + hero1.name + " Wins"))
}
}
console.log(result)
}
First shuffle the array:
let heroes = [daredevil, hulk, tonyStark, magneto, unknown, xavi]
let heroes_shuffle = heroes.sort((a, b) => 0.5 - Math.random())
Then do as normal
getPairs(heroes_shuffle )
All Possible Combination :
function allPairs(heroes) {
while (heroes) {
[hero, ...heroes] = heroes
for (enemy of heroes) {
if (hero.markAv === enemy.markAv)
console.log(hero.name + " vs " + enemy.name + ": draw")
else if (hero.markAv < enemy.markAv)
console.log(hero.name + " vs " + enemy.name + ": " + enemy.name + " Wins")
else
console.log(hero.name + " vs " + enemy.name + ": " + hero.name + " Wins")
}
}
}
You can take the function from here https://stackoverflow.com/a/7228322/1117736
And do something like this:
class Avenger {
constructor(name, classRoom, city, job, studies, markAv, id) {
this.name = name;
this.classRoom = classRoom;
this.city = city;
this.job = job;
this.studies = studies;
this.markAv = markAv;
this.id = id;
}
heroList() {
return this.name + " " + this.classRoom + " " + this.city + " " + this.job + " " + this.studies + " " + this.markAv + " " + this.id
}
}
const tonyStark = new Avenger("Tony Stark", "XI", "NYC", "Ingeneer", "MIT", 10, 1)
const hulk = new Avenger("Hulk", "X", "Toledo", "Destroyer", "Scientific", 7, 2)
const daredevil = new Avenger("Daredevil", "IX", "NYC", "Lawyer", "Fighter", 2, 3)
const magneto = new Avenger("Magneto", "XXI", "SBD", "Unemployed", "Driver", 5, 4)
const unknown = new Avenger("Unknown", "L", "CDY", "President", "Clerck", 17, 5)
const xavi = new Avenger("Xavi", "XX", "BCN", "Analist", "Calle", 7, 6)
let heroes = [daredevil, hulk, tonyStark, magneto, unknown, xavi]
function randomIntFromInterval(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min)
}
let hero1 = heroes[randomIntFromInterval(1, 6)]
let hero2 = heroes[randomIntFromInterval(1, 6)]
if (hero1.markAv < hero2.markAv) {
console.log(hero1.name + " vs " + hero2.name + " " + hero1.name + " Wins")
} else if(hero1.markAv > hero2.markAv) {
console.log(hero1.name + " vs " + hero2.name + " " + hero2.name + " Wins")
}
I am building a text based choice RPG game using Javascript. I am able to add functions inside of an object and run them, however, I want the function to run if the option ( text node ) is chosen.
Currently, I declare a function, and then call it at the bottom of the page. The issue is, I want to function to run as soon as the choice is chosen.
Here is the code I have so far...
function addRadiatedStatus(){
character.radiated = true;
}
const textNodes = [
{
id: 1,
text: "Do you want to help this person?",
options: [
{
text: "Yes",
nextText: 2
},
{
text: "No",
nextText: 2
},
],
faction: "Greaser"
},
{
id: 2,
text: "It was a trap, do you run or kill them?",
options: [
{
text: "Run",
nextText: 3,
damage: 0,
},
{
text: "Kill",
nextText: 5,
damage: 8,
moneyDrop: 20,
radiationDamage: 2,
function: function update(){
if(character.greaser == true && textNodes[1].faction ==
"greaser"){
console.log("greaser check worked");
}
console.log("upadte function worked")
character.health -= this.damage;
character.cash += this.moneyDrop;
character.radiationLevel += this.radiationDamage;
character.maxHP -= this.radiationDamage;
if(this.radiationDamage >= 1 ){
addRadiatedStatus();
}
console.log("character HP" + " " + character.health);
console.log("character maxHP" + " " + character.maxHP);
console.log("moneyDrop " + " " + this.moneyDrop);
console.log("character cash" + " " + character.cash);
console.log("radiation level" + " " + character.radiationLevel);
console.log("character Raditated?" + " " + character.radiated);
}
}
],
faction: "Greaser",
}
]
textNodes[1].options[1].function();
I tried a few different things, including adding another key run: update() , run: this.update(), run: this.function, etc.
I am also a little confused because I thought that ES6 allows me to remove the function keyword, but that doesn't seem to be allowed ( I am probably just doing it wrong, or running into an issue based on how I set up my object ).
I am not sure how to go from calling textNodes[1].options[1].function to dynamically calling whichever function is nested within a specific choice option.
Thanks in advance for the help.
You can change this section to this:
update: (function(){
console.log("upadte function worked")
character.health -= this.damage;
character.cash += this.moneyDrop;
character.radiationLevel += this.radiationDamage;
character.maxHP -= this.radiationDamage;
if(this.radiationDamage >= 1 ){
addRadiatedStatus();
}
console.log("character HP" + " " + character.health);
console.log("character maxHP" + " " + character.maxHP);
console.log("moneyDrop " + " " + this.moneyDrop);
console.log("character cash" + " " + character.cash);
console.log("radiation level" + " " + character.radiationLevel);
console.log("character Raditated?" + " " + character.radiated);
});
The function keyword has been changed to update, then the function has been changed to an anonymous function ... You should refrain from using js keywords for your user-defined ones.
Then the anonymous function will not execute until you call it:
textNodes[1].options[1].update()
Here's an example of what I'm talking about:
This shows that you have to actually access the function and any other key for that matter for you to access the values.
var text = [
{
data1: "here",
data2: (function(){
return "You have to explicitly call me!"
})
}
]
console.log("Without calling any data: " + text[0])
console.log("When you call data2: " + text[0].data2())
console.log("Let us access data1: " + text[0].data1)
I have a JSON which I query with xhr. The objects (person) contain a key-value pair called "serviceLevel" that I have to split.
When I stack this in a variable (services) and log it like this:
let main = document.getElementsByTagName('main');
getXHR("GET", './db/orga.json', (success) => {
format(success)
}, (error) => {
console.error(error)
});
function format() {
let people = arguments[0];
for (let i in people) {
let person = people[i];
let services = person.serviceLevel.split(".");
console.log(services);
console.log(person.serviceLevel.split("."));
let idCard = document.createElement('div');
idCard.id = person.firstName + person.familyName;
idCard.classList.add('person');
idCard.innerHTML = "<div class=\"item nom\"><span class=\"prenom\">" + person.firstName + "</span><span class=\"famille\">" + person.familyName + "</span></div>";
idCard.innerHTML += "<span class=\"job\">" + person.jobTitle_1 + "</span>";
idCard.innerHTML += "<span class=\"mail\"><a href=\"mailto:" + person.mail + "\">" + person.mail + "</span>";
idCard.innerHTML += "<span class=\"tel\"><a href=\"tel:" + person.phone_1 + "\">" + person.phone_1 + "</span>";
idCard.innerHTML += "<span class=\"tel\"><a href=\"tel:" + person.mobile + "\">" + person.mobile + "</span>";
for (let j in services) {
let serviceElement = document.getElementById(services[j]);
if (!serviceElement) {
let serviceElement = document.createElement('div');
serviceElement.id = services[j];
serviceElement.classList.add('n' + j, "service");
serviceElement.innerHTML = "<span class=\"title\">" + services[j] + "</span>";
if (j == 0) {
if (services[services.length - 1] = j) {
serviceElement.appendChild(idCard);
main[0].appendChild(serviceElement);
}
} else {
let parent = services[j - 1],
parentService = document.getElementById(parent);
if (services[services.length - 1] = j) {
serviceElement.appendChild(idCard);
}
parentService.appendChild(serviceElement);
}
} else {
serviceElement.appendChild(idCard);
}
}
}
}
const data = [{
"Tri": "blablablabla, CSMSI.SAFS, n, XXXX, YYYY",
"Department": "The best department",
"serviceLevel": "CSMSI.SAFS",
"organisationLevel": "blablablabla",
"rang": "n",
"familyName": "XXXX",
"firstName": "YYYY",
"jobTitle_2": "Directeur",
"jobTitle_1": "Directeur",
"phone_1": "nn nn nn nn nn",
"phone_2": "",
"mobile": "nn nn nn nn nn",
"mail": "xxxx.yyyy#zzzz.fr",
"location": "france"
}];
format(data);
The results are different:
(2) ["CSMSI", "SAFS"]
0: "CSMSI"
1: "SAFS"
length: 2
(2) ["CSMSI", "SAFS"]
0: "CSMSI"
1: "1"
length: 2
As we can see, content of "services" are good, but when I extend the tree, the value of the second key value is "1" ... which is a problem. Is there a way to change this?
when I use a for loop with "classical" (i = 0; i < people.length; i++), i don't have the problem....
is there a standard established way to do the following:
curl -i "http://api.waqi.info/feed/shanghai/?token=demo"
returns
{
status: "ok",
data: {
aqi: 70,
time: {
s: "2016-12-11 12:00:00"
},
city: {
name: "Shanghai",
url: "http://aqicn.org/city/shanghai/",
geo: [
"31.2047372",
"121.4489017"
]
},
iaqi: {
pm25: "..."
}
}
}
i want to make a simple page that calls the API and formats the result. but i want to do it in the browser so that i can host a serverless webpage.
Ive look at Angular and react but it seems an awful lot of setup and baggage to do something simple like this.
i could write the jscript and html from scratch but also feels like there should be some libraries to support this.
You can write an ajax call to get the data like this:
fetch('http://api.waqi.info/feed/shanghai/?token=demo')
.then(function(response) {
return response.json();
})
.then(function(jsonData) {
console.log(jsonData); //the data you want to get
});
More information here
If you want to use some library, you can try superagent
I have used jQuery plugin and used $.ajax() method: See here.
Later, I split all data using keys as shown below;
$.ajax({
url: 'http://api.waqi.info/feed/shanghai/?token=demo',
success: function(ajax) {
console.log(ajax);
let data = ajax.data; // Object
let api = data.api; // Int
let attributions = data.attributions; // Array [3]
let cityCoords = data.city.geo; // Array [2]
let cityName = data.city.name; // String
let cityUrl = data.city.url; // String
let dominentpol = data.dominentpol; // String
let iaqi = data.iaqi; // Object Keys = [co, d, h, no2, o3, p ,pm10, pm25, so2, t, w, wd]
let idx = data.idx; // Int
let time = data.time; // Object Keys = [s, tz, v]
let status = ajax.status;
console.log("Data Object: "
+ data +
"\nAPI Version: "
+ api +
"\nAttributions #1 Name: "
+ attributions[0].name +
"\nAttributions #1 Url: "
+ attributions[0].url +
"\nAttributions #2 Name: "
+ attributions[1].name +
"\nAttributions #2 Url: "
+ attributions[1].url +
"\nAttributions #3 Name: "
+ attributions[2].name +
"\nAttributions #3 Url: "
+ attributions[2].url +
"\nCity Longitude: "
+ cityCoords[0] +
"\nCity Latitude: "
+ cityCoords[1] +
"\nCity Name: "
+ cityName +
"\nCity Url: "
+ cityUrl +
"\dDominentpol: "
+ dominentpol +
"\nIaqi Key [co]: "
+ iaqi.co +
"\nIaqi Key [d]: "
+ iaqi.d +
"\nIaqi Key [h]: "
+ iaqi.h +
"\nIaqi Key [no2]: "
+ iaqi.no2 +
"\nIaqi Key [o3]: "
+ iaqi.o3 +
"\nIaqi Key [p]: "
+ iaqi.p +
"\nIaqi Key [pm10]: "
+ iaqi.pm10 +
"\nIaqi Key [pm25]: "
+ iaqi.pm25 +
"\nIaqi Key [so2]: "
+ iaqi.so2 +
"\nIaqi Key [t]: "
+ iaqi.t +
"\nIaqi Key [w]: "
+ iaqi.w +
"\nIaqi Key [wd]: "
+ iaqi.wd +
"\nIdx: "
+ idx +
"\nTime Key = [s]: "
+ time.s +
"\nTime Key = [tz]:"
+ time.tz +
"\nTime Key = [v]:"
+ time.v +
"\nStatus: "
+ status);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
How can I get javascript to read the values "at the end" of the json list below.
i am currently using the code below, except that this code does not read the last 3 values, with different formatting, of the list below i.e.
Extract of Json list:
{...... 'Design_Lump_Sum': {0: {'** Preliminary Design': '2366. 0'},
1: {'** Detailed Design': '15379.0'}, 2: {'** Const Stage Services':
'4732.0'}} }
Code:
var obj = JSON.parse(data);
var keys = Object.keys(obj.Design_Lump_Sum);
for (var asset in keys) {
console.log(asset + " -> " + keys[asset] + " = " + obj.Design_Lump_Sum[keys[asset]]);
}
var keys1 = Object.keys(obj.Capex_Lump_Sum);
for (var asset in keys1) {
console.log(asset + " -> " + keys1[asset] + " = " + obj.Design_Lump_Sum[keys1[asset]]);
}
var keys2 = Object.keys(obj.Opex_Lump_Sum);
for (var asset in keys2) {
console.log(asset + " -> " + keys2[asset] + " = " + obj.Design_Lump_Sum[keys2[asset]]);
}
var keys3 = Object.keys(obj.Provisional_Sum);
for (var asset in keys3) {
console.log(asset + " -> " + keys3[asset] + " = " + obj.Design_Lump_Sum[keys3[asset]]);
}
var keys4 = Object.keys(obj.Management_fees);
for (var asset in keys4) {
console.log(asset + " -> " + keys4[asset] + " = " + obj.Design_Lump_Sum[keys4[asset]]);
}
var keys5 = Object.keys(obj.CSA);
for (var asset in keys5) {
console.log(asset + " -> " + keys5[asset] + " = " + obj.Design_Lump_Sum[keys5[asset]]);
}
Full JSON list:
{
"Management_fees":{ },
"Capex_Lump_Sum":{
"Refrigerant piping":"48040.447",
"Preparation of Mops":"2137.681",
"Labels":"653.016",
"Penetrations and Protection":"1535.534",
"AC Plinth and Trays":"5221.762",
"Insulated Panel Windows":"6527.794",
" MSSB":"19582.199",
"Make Good Walls and Floors":"4154.696",
"Controls":"24092.978",
"** Building Surveyor Fee (Misc)":"7038.85",
"Project Management, Supervision":"38447.5",
"Painting":"9138.675",
"Preliminaries":"1306.032",
"Package system wiring":"16971.318",
"Warranty":"2610.881",
"Ductwork, Valves and Dampers":"77262.913",
"Unit type":"89107.109",
"Structural Engineer for new unit stands":"3916.913",
"Manuals":"3823.456",
"AMS and BMS works":"3916.913",
"Accoustic Report":"4243.421",
"Lighting":"5033.665",
"Drawings":"3823.456",
"Temp Cooling":"10443.524",
"Commissioning":"3263.897",
"Crane":"3003.637",
"Demolition":"26455.429",
"Fire detection and Alarm FIP modifications":"3263.897",
"LSL":"1939.81059657",
"Economy Cycle":"23169.055"
},
"Provisional_Sum":{
"Condenser Roof Platform":"20000.0",
"Removal of ladder outside cable chamber exit stairs":"10000.0"
},
"Opex_Lump_Sum":{ },
"CSA":{
"Additional Hendry Fees":"3742.5",
"External Ladder":"10147.0",
"Asbestos removal Works Total ($42,485.15) (remainder of cost $30K under PS sum)":"12485.15"
},
"Design_Lump_Sum":{
"0":{
"** Preliminary Design":"2366.0"
},
"1":{
"** Detailed Design":"15379.0"
},
"2":{
"** Const Stage Services":"4732.0"
}
},
"Total":{
"sub_Total":"number:530154.0105965699"
}
}
If I don't misunderstood your question then you can try like this.
var obj={'Management_fees':{},'Capex_Lump_Sum':{'Refrigerant piping':'48040.447','Preparation of Mops':'2137.681','Labels':'653.016','Penetrations and Protection':'1535.534','AC Plinth and Trays':'5221.762','Insulated Panel Windows':'6527.794',' MSSB':'19582.199','Make Good Walls and Floors':'4154.696','Controls':'24092.978','** Building Surveyor Fee (Misc)':'7038.85','Project Manag ement, Supervision':'38447.5','Painting':'9138.675','Preliminaries':'1306.032','Package system wiring':'16971.318','Warranty':'2610.881','Ductwork, Valves and Dampers':'77262.913','Unit ty pe':'89107.109','Structural Engineer for new unit stands':'3916.913','Manuals':'3823.456','AMS and BMS works':'3916.913','Accoustic Report':'4243.421','Lighting':'5033.665','Drawings':'38 23.456','Temp Cooling':'10443.524','Commissioning':'3263.897','Crane':'3003.637','Demolition':'26455.429','Fire detection and Alarm FIP modifications':'3263.897','LSL':'1939.81059657','Ec onomy Cycle':'23169.055'},'Provisional_Sum':{'Condenser Roof Platform':'20000.0','Removal of ladder outside cable chamber exit stairs':'10000.0'},'Opex_Lump_Sum':{},'CSA':{'Additional Hendry Fees':'3742.5','External Ladder':'10147.0','Asbestos removal Works Total ($42,485.15) (remainder of cost $30K under PS sum)':'12485.15'},'Design_Lump_Sum':{0:{'** Preliminary Design':'2366. 0'},1:{'** Detailed Design':'15379.0'},2:{'** Const Stage Services':'4732.0'}},'Total':{'sub_Total':'number:530154.0105965699'}};
var data = obj.Design_Lump_Sum;
Object.keys(data).map(function(item,index){
Object.keys(data[item]).map(function(key) {
console.log(key, "->", data[item][key]);
});
});