I have edited the question. Changed to syntax error and it is still not working. I'm using github api to get list of users and then for each user - to get his repos. My idea was to get all repos (which I got) and when it is all done, to put the allRepos array in the user object, and then to return the user object so I can render it. I've done it by foreach loop inside of Promise.all. I know I'm not using it correctly, because I can't use the .then() after the Promise.all. Is it possible to use the Promise.all the way I need or do I have to define the array I'm putting into it in advance? Help would be appreciated.
function onGetUsers() {
// var prmUsers=getUsers()
getUsers()
.then(getrepos)
.then(data=> console.log(data))//here i want to render the object
}
function getrepos(users){
var usersObj={
users: users,
}
var allRepos = []
Promise.all(users.forEach(user => {
var currUser = axios.get(user.repos_url)
.then(data => allRepos.push(data));
return currUser;
})).then('here i want to put allRepos in the usersObj')
return usersObj
}
function getUsers() {
var prmRes = axios.get('https://api.github.com/users');
var prmUsers = prmRes.then(res => {
return res.data;
});
return prmUsers;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/index.css">
<title>Github Users</title>
</head>
<body>
<button onclick="onGetUsers()">Get Users</button>
<script src="lib/axios.js"></script>
<script src="js/index.js"></script>
</body>
</html>