Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda