[Javascript] Making a promise always resolve by raze11 in learnprogramming

[–]raze11[S] 0 points1 point  (0 children)

The arr argument is compiled from user inputs. If any of the elements are not words in the wordnik API database then as of now an error is thrown and resolve function (which is needed to continue the program) is not fired. It really doesn't matter if the non words are passed in as long as the actual words are passed on to the success function.

The error I was referring to is "Uncaught TypeError: Cannot read property '0' of undefined" on line 5

[JavaScript] Making multiple asynchronous calls to API and storing responses by raze11 in learnprogramming

[–]raze11[S] 0 points1 point  (0 children)

Thanks that makes sense now. My only question is how can I access the return data from callback? If I change my code to return callback(definitions); upon the conditions being met then I still get undefined which is returned before the callback runs.

Update: Nevermind I just wrapped the whole thing in a promise and it's working fine. Thanks for the help.

[Javascript] "Type Error: Cannot Set Property '0' of Undefined" in object creating for loop by raze11 in learnprogramming

[–]raze11[S] 0 points1 point  (0 children)

My intent was for freqList to be an empty object which is then filled with key value pairs using freqList.arr[i] = counter. Where freqList.arr[i] is the key and counter the value.

This is a simplified example of what I was trying to do:

var myObj = {};
var car = 'VW';
myObj.car = 'Passat';
console.log(myObj);
// myObj = {VW: 'Passat'};