0

my javascript code stop executing when I try to access the length property from my passed array.

var arrParams = getParams(url);
var strRef = getRef(arrParams);

function getRef(pv_arrParams)
{
    portFromCS.postMessage({greeting: 'before .length'});
    portFromCS.postMessage({greeting: pv_arrParams.length}); <- no log
    .
    .
    .
}

the array is not null or empty. When I debug its works fine but not otherwise.

edit: here is an example. Its a Firefox addon https://www.file-upload.net/download-12913625/example.rar.html

so when I debug its not empty or undefined:

enter image description here

BR75
  • 633
  • 7
  • 25
  • 4
    You're probably having this problem: https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – Khauri Jan 09 '18 at 13:56
  • Show `console.log(pv_arrParams);` – Sankar Jan 09 '18 at 13:57
  • Check its an array or not? – zabusa Jan 09 '18 at 13:59
  • Please provide a [mcve] – charlietfl Jan 09 '18 at 13:59
  • there is no ajax. when I log the pv_arrParams before I call my getRef-function I get undefined but when I debug its works like a charm. So its very strange for me. just uploaded my code – BR75 Jan 09 '18 at 14:19
  • You set `url` inside a `.then` block. You may want to take a look at the `ES2015+: Promises with then()` section of the linked question? The debugger is very likely executing and grabbing the state after the `.then` block has had a chance to run. – Dre Jan 09 '18 at 15:32
  • So do I have to work with await here? – BR75 Jan 09 '18 at 18:03

0 Answers0