Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!