最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Firebase Functions print an object to the console - Stack Overflow

programmeradmin0浏览0评论

I have this code on the Firebase cloud using functions

peopleDataBase.orderByChild("mCalculateFaceSizeWidth")
                        .endAt(mCalculateFaceSizeWidth())
                        .limitToLast(1)
                        .on("child_added", function(snapshot) {
                       var  person = {
                                "name":snapshot.val().name,
                                "age":snapshot.val().age,
                                "id":snapshot.val().id,
                                "children":snapshot.val().children,
                                "address":snapshot.val().address,
                                "image":snapshot.val().image
                            }

                            if(key != snapshot.key){
                                people += person;
                                key = snapshot.key;
                                console.log("The entire people list:",people);
                            }

                        });

I am trying to print the people object to the console, I have searched for an hour using JSON.stringify and String even $scope and other methods, nothing worked. In the log on the cloud I am getting

2017-07-11T07:55:54.593Z I status: The entire people list: [object Object]

Eventually I want to send the object back to the mobile device but I want to make sure I see the data inside. Ideas?

Thanks Eran

I have this code on the Firebase cloud using functions

peopleDataBase.orderByChild("mCalculateFaceSizeWidth")
                        .endAt(mCalculateFaceSizeWidth())
                        .limitToLast(1)
                        .on("child_added", function(snapshot) {
                       var  person = {
                                "name":snapshot.val().name,
                                "age":snapshot.val().age,
                                "id":snapshot.val().id,
                                "children":snapshot.val().children,
                                "address":snapshot.val().address,
                                "image":snapshot.val().image
                            }

                            if(key != snapshot.key){
                                people += person;
                                key = snapshot.key;
                                console.log("The entire people list:",people);
                            }

                        });

I am trying to print the people object to the console, I have searched for an hour using JSON.stringify and String even $scope and other methods, nothing worked. In the log on the cloud I am getting

2017-07-11T07:55:54.593Z I status: The entire people list: [object Object]

Eventually I want to send the object back to the mobile device but I want to make sure I see the data inside. Ideas?

Thanks Eran

Share Improve this question edited Jul 11, 2017 at 13:44 Frank van Puffelen 600k85 gold badges889 silver badges859 bronze badges asked Jul 11, 2017 at 8:11 user3906716user3906716 2
  • 1 well the log is true your array have 2 object, object can not be parsed directly you can use JSON.stringify(people); – Oussema Aroua Commented Jul 11, 2017 at 8:47
  • I already tried it, did not work. I tried this console.log(JSON.stringify(people)); I am getting: 2017-07-11T09:13:39.483Z I status: "[object Object]" – user3906716 Commented Jul 11, 2017 at 9:10
Add a ment  | 

3 Answers 3

Reset to default 5

I had similar issue. I had to print it without string concatenation:

console.log("The entire people list:");
console.log(people);

This works for me:

console.log("The entire people list:", JSON.stringify(people));

just console.log snap.val() to see the response. Add if(snap.val().whateverProperty logic.

发布评论

评论列表(0)

  1. 暂无评论