Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Access array from other function

Hello i’m trying to access an array from a function what i’am returning work, it’s an array but the result in my function "onChangeClient" always display the same "undefined". why ?

Typescript:

1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

JavaScript (and hence TypeScript) uses lexical scope, meaning you cannot create an Array in an inner function and access it from outside. What you can do: Create the array in the outer function (getRessource) and return it from there.

async getRessource(id) {
  var ref = ... elided ...
  const returnArray = []; // define it here
  await ref.once('value' ... elided ... );
  return returnArray;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading