JavaScript Return complete array from Promise

I am not very sure as I am not able to try this, but looks like you have scoping problem here, try to do this.

     function updateTopStories() {
        var tempStoriesArr = [];

        hnews.getIdsInCategory('topstories', 60)
        .then(function(ids) {
            ids.forEach(function(id) {
                hnews.getById(id).then(function(story) {
                    console.log(story);
                    tempStoriesArr.push(story);
                });
            });
        });
        return tempStoriesArr;
    }

    var StoriesArr = updateTopStories();
    console.log(StoriesArr);
Answer:1

You could reconstruct your response from each call as:

function updateTopStories() {
    var storiesArr = {};

    hnews.getIdsInCategory('topstories', 60)
    .then(function(ids) {
        ids.forEach(function(id) {
            storiesArr[id] = [];
            hnews.getById(id).then(function(story) {
                console.log(story);
                storiesArr[id].push(story);
            });
        });
    });
    return storiesArr;
}

updateTopStories();

Here you are initializing each story for a particular id group which is an array and then you can retrieve each story based on the id's.

Answer:2

I am trying to understand why my SVG icon is not rendered correctly. The icon is a little smallest that my SVG element event if the viewBox property was used the same like width\height. Thanks for ...

I am trying to understand why my SVG icon is not rendered correctly. The icon is a little smallest that my SVG element event if the viewBox property was used the same like width\height. Thanks for ...

  1. max-width isn't working
  2. css width isn't working
  3. max-width isn't a valid css value

I'am trying to sign into Skype via the use of its SDK but I keep hitting the following error, "Error: NoFQDN". After searching this on the net I can't find any possible solution or even find out what ...

I'am trying to sign into Skype via the use of its SDK but I keep hitting the following error, "Error: NoFQDN". After searching this on the net I can't find any possible solution or even find out what ...

  1. skype entry point not found
  2. skype entry point not found error
  3. skype entry point not found ffmpeg.dll
  4. skype entry point
  5. skype entry point not found avcodec_decode_audio4
  6. skype entry point not found windows 7
  7. skype entry point not found iphlpapi.dll
  8. skype.exe entry point not found
  9. skype.exe entry point not found windows 10
  10. skype procedure entry point
  11. skype.exe entry point not found fix
  12. skype.exe entry point not found windows xp
  13. skype procedure entry point not found
  14. skype.exe entry point not found iphlpapi.dll
  15. skype no entry point
  16. skype the procedure entry point avcodec_decode_audio4
  17. skype for business entry point not found
  18. skype.exe the procedure entry point ntdll.dll
  19. lỗi skype entry point not found

I have researched this issue and have found solutions using php but not angular. One of the requirements for saving the data on my page requires that two seperate angular objects have the same Id. ...

I have researched this issue and have found solutions using php but not angular. One of the requirements for saving the data on my page requires that two seperate angular objects have the same Id. ...

  1. angularjs change active tab

I'm currently working on a project using webpack and babel to build a project. I tried so many things as I can think of, but somehow onSubmit or onClick function do not work no matter how I bind those ...

I'm currently working on a project using webpack and babel to build a project. I tried so many things as I can think of, but somehow onSubmit or onClick function do not work no matter how I bind those ...

  1. react onsubmit is not a function
  2. react form onsubmit do nothing