I am working with Github API using Octokit library.
I have a function which list out all the repository of a user(username). I have called this function on click of a button called Fetch
For sake of simplicity, I am rendering out only 1st repository(using index 0).
const list = []
function fetchRepos() {
octokit.repos
.listForUser({
username: 'abhinav-anshul',
})
.then((details) => list.push(details.data[0].name))
console.log('List Array', list)
const list2 = [...list]
console.log(list2)
}
As we can see in the code, I am handling a promise chain, and in that promise chain, I am pushing the repo result in the empty array called list.
In the console.log('List Array', list)
, I am able to get the '0th' repo name correctly, as given in the image below:
But when I try to use spread operator
to pass the list array to a new array called list2
and do a console.log(list2)
I get the following :
Why I have lost the name of the repo here? Am I doing something conceptually wrong? Any help is really appreciated.
Thank you