Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
get data from return in nested function

I'm pretty new to js and this topic is tricky to me. How can I turn my code below to a function which takes one argument (username) retrieves data from database, and returns profile pic url? I mean 'newadmin' will be an argument passed to a function which i will call here, so i can use this profile pic in my entire website

const src = ref(database, `users/newadmin`);
const profpic = () => {
    get(child(ref(database), "users/newadmin/profile_picture"))
        .then((snapshot) => {
            if (snapshot.exists()) {
                console.log(snapshot.val());
            } else {
                console.log("no data");
            }
        })
        .catch((error) => {
            console.error(error);
        });
};
profpic();

i tried this, returns undefined:

const src = ref(database, `users/newadmin`);
const profpic = () => {
    var result;
    get(child(ref(database), "users/newadmin/profile_picture"))
        .then((snapshot) => {
            if (snapshot.exists()) {
                result = snapshot.val();
                return result;
            } else {
                console.log("no data");
            }
        })
        .catch((error) => {
            console.error(error);
        });
};
var x = profpic();
console.log(x);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!