I was learning JS specifically promises with async await and faced an issue while implementing await and async , I am not getting my output. SO what i I was trying to do is that I want to do task Task1 : print the rollnumber array after 2 sec task 2 : passing rollnoarr[1] and printing the object created.
Kindly help me out with my code. Thank you.
const pobj1 = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
let rollno = [1, 2, 3, 4, 5];
resolve(rollno);
}, 2000);
})
}
const getBiodata = (indexdata) => {
console.log("getbiodata called");
return new Promise((resolve, reject) => {
setTimeout((indexdata) => {
const mydata = {
name: "Harshit",
age: 22
}
console.log(`my name is ${mydata.name} and my age is ${mydata.age} and my rollno is ${indexdata}`);
}, 2000, indexdata);
})
}
const callMe = async() => {
const obj1 = await pobj1();
console.log(obj1);
const obj2 = await getBiodata(obj1[1]);
console.log(obj2);
}
callMe();