Javascript - Array of various objects, but with content

Asked

Viewed 21 times

0

The problem in question is that I do the request, I receive the data, I push the data inside an instantiated array at the beginning of the code, but when I go to see this array, it says it’s empty, when I open to see what’s inside, it has the data I push.

I tried to give him length, but it gives zero;
I tried to take a value from inside it, but from Undefined;
No error on console

That is the code

  // eslint-disable-next-line prefer-const
  let teamates = [];

  useEffect(() => {
    axios({
      method: 'get',
      url: 'https://api.github.com/orgs/Liga-dos-Programadores/members'
    }).then((response) => {
      const { data } = response;
      // console.log(data);
      for (let i = 0; i < data.length; i += 1) {
        // console.log(data.length);
        axios({
          method: 'get',
          url: data[i].url
        }).then((res) => {
          // console.log(res.data);
          teamates.push({
            name: res.data.name,
            avatar: res.data.avatar_url,
            website: res.data.blog,
            twitter: res.data.twitter_username,
            email: res.data.email,
            username: res.data.login
          });
        });
      }
      console.log(teamates);
    });
  }, []);

And this is the return

inserir a descrição da imagem aqui

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.