Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
Retrieving values from array throws error javacript

I am having an array with following values:

 [
  {
    'Admin1': {
      id: 'fa1b2731'
     
    },
    'Admin2': {
      id: '7b5ab064'
     
    },
    'Admin3': {
      id: '9f462511'
     
    },
    'Admin4': {
      id: 'aa82421d'
    
    },
    'Admin5': {
      id: '34cb2b'
     
    },
    'Admin6': {
      id: 'ff71ffdd'
    
    },
    'Admin7': {
      id: 'b57ac9e7'    
      
    }
  }
] 

The code i am trying to retrieve each user id from above array is throwing an error->expected undefined not to be undefined Following is the code snippet:

 if (userArray) {    
    for (const user of Object.values(userArray)) {
      const delUserRes = await userApi.deleteUserById({
        token: accessToken,
        organizationId: orgid;,
        userId: user.id
      });

the above method reads the userarray corectly but never assign each id to userId form user.id and throws error

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

The array in example is having one item, what i mean to get user.id you should call array[0].['Admin1'].id. In your code you doing it like array.['Admin1'].id, so thats why it can't find user.id.

try something like this

 if (userArray) {    
    for (const user of Object.values(userArray[0])) {
      const delUserRes = await userApi.deleteUserById({
        token: accessToken,
        organizationId: orgid;,
        userId: user.id
      });
about 4 years ago · Juan Pablo Isaza Denunciar

0

Your all the user are in single element of array object at 0 index. try below code

 for (const user of Object.values(userArray[0])) {
console.log(user) 
 }

about 4 years ago · Juan Pablo Isaza Denunciar

0

Basically you are trying to get values from an object inside an array, so the Object.values doesn't make sense in your code. You can simply use userArray[0] in your for loop or map like:

var data = [ { 'Admin1': { id: 'fa1b2731' }, 'Admin2': { id: '7b5ab064' }, 'Admin3': { id: '9f462511' }, 'Admin4': { id: 'aa82421d' }, 'Admin5': { id: '34cb2b' }, 'Admin6': { id: 'ff71ffdd' }, 'Admin7': { id: 'b57ac9e7' } } ] 

Object.values(data[0]).map(user => {   //your logic here } );
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda