I am stuck in a very weird issue. I have done this so many times previously but this time it's just not working and I am stuck.
var updateObj = {};
db.child("symbols/" +name).once('value').then(function(data){
if(data.exists())
ticker.val().forEach(function(path){
addInJSON(path, data.val());
});
})
//Trying to add some dummy values to test
addInJSON("dummy", {val: "pummy"});
updateObj["dummykey"] = "dummy value";
for(key in updateObj){
console.log(key + " " + updateObj[key]);
}
function addInJSON(key, value){
updateObj[key] = value;
}
Output looks like this: Output looks like this:
Object {dummy: Object, dummykey: "dummy value"}
dummy:Object {val: "pummy"}
dummykey:"dummy value"
watchlist/41HJ5vonrUMMkH7TDwiSdAedhEL2/ADANIPOWER:Object {day_change: 2.25, day_change_percentage: 6.17, day_high: 40.05, …}
watchlist/41HJ5vonrUMMkH7TDwiSdAedhEL2/ARVIND:Object {day_change: -2.75, day_change_percentage: -0.6, day_high: 462.15, …}
watchlist/41HJ5vonrUMMkH7TDwiSdAedhEL2/ASHOKLEY:Object {day_change: 0.05, day_change_percentage: 0.04, day_high: 118.85, …}
PROBLEM
output: Object {dummy: Object, dummykey: "dummy value"}
Expected output: Object {dummy: Object, dummykey: "dummy value", "watchlist/41HJ5vonrUMMkH7TDwiSdAedhEL2/ADANIPOWER" :Object, ...}
To add
values to objects
you would do this myObject['someKey'] = 'someValue'
. But if you wanted to add values differently I added an example for that as well. Try the snippet
to see.
// Example 1 var myObject = {}; myObject['first'] = {}; myObject['second'] = {}; myObject['first']['firstFirst'] = 5; myObject['first']['firstSecond'] = 6; myObject['second']['secondFirst'] = 1; myObject['second']['secondSecond'] = 9; console.log("This is example 1."); console.log(myObject); // Example 2 var myObject2 = {}; Object.assign(myObject2, { first: { firstFirst: 5, firstSecond: 6 } }); Object.assign(myObject2, {second: { secondFirst: 1} }); Object.assign(myObject2['second'], { secondSecond: 9 }); console.log("\\nThis is example 2"); console.log(myObject2);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.