How to address an array with double-curly braces

48 Views Asked by At

I am working with testing and accessing credentials from an array called "creds" that contains a set of 15 username/password pairs.

[
{user: 'user', password: 'password'}
{user2: 'user2', password2: 'password2'}
.......
]

This code grabs the first set of values in the array:

//if there are no credentials left to be used, wait and check 
again.   If not, return the first credential in the array. 
while (creds.length === 0) {
    // Wait for 100 ms and check again
    await new Promise((resolve) => setTimeout(resolve, 100))
    }
    // Dequeue a credential and return it
    return creds.shift()

What is returned by this is:

{ { username: 'username', password: 'password'} }

The problem is that I can't access them using the array.username/array.password method, because of the extra curly braces around them. How do I get this to either NOT add/return the object with the extra curly braces, or access the values inside regardless of the curly braces.

currently, trying to use array.username/array.password just returns undefined.

0

There are 0 best solutions below