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

144
Vistas
Two Arrays: One validates what content will be displayed from the other - with JavaScript

I have two Arrayes that has been sourced from two different URIs. I am trying to create a form of code that extracts specific data from one Array and connects it to related data from the other Array. Here's an example:

let coursesData = ['teachers': 'CHCH'];

let teacherData = [
{
'id': {'name': 'CHCH'},
'name':{ 
'jobtitle': 'Professor',
'firt':'Charie',
'last': Chaplin 
},
}];

function renderCourseTeachersList () {

  teacherData
    .filter(object => {
      return object.id.includes(parseInt(coursesData.teachers));
    })
    .forEach((item, i) => {
      console.log(`Lärare: ${item.name.jobtitle} ${item.name.first} ${item.name.last}`);
  });
}

I was hoping this would give me a list of the values: jobtitle, first and last in the console log, in order of the matching value: CHCH.

The two arrays are just snippets of a larger source.

Thank you in advance!

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

0

As you put a snippet of your source data, I guess coursesData is an array of objects. So I defined multiple objects in coursesData. If your structure is different, Snippet will provide you idea to get the expected result.

let coursesData = [ 
    {
        'teachers': 'CHCH'
    },
    {
        'teachers': 'xyz'
    },
];

let teacherData = [
    {
        'id': {
            'name': 'CHCH'
        },
        'name': { 
            'jobtitle': 'Professor',
            'first': 'Charie',
            'last': 'Chaplin',
        },
    },
    {
        'id': {
            'name': 'xyz'
        },
        'name': { 
            'jobtitle': 'Lecturer',
            'first': 'John',
            'last': 'Doe',
        },
    }
];

function renderCourseTeachersList (){
    teacherData.filter(object => coursesData.some(subItem => subItem.teachers == object.id.name))
    .forEach((item, i) => {
        console.log(`Lärare: ${item.name.jobtitle} ${item.name.first} ${item.name.last}`);
    });
}

renderCourseTeachersList();

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