My task is to filter out all Portfolio Lead
who have English Competency
set to No
.
var data = [{
"Employee Number": 138,
"English Competency": "No",
"Portfolio Lead": "x",
"Maths Competency": "No"
},
{
"Employee Number": 1385,
"English Competency": "yes",
"Portfolio Lead": "x",
"Maths Competency": "yes"
},
{
"Employee Number": 1318,
"English Competency": "yes",
"Portfolio Lead": "y",
"Maths Competency": "No"
},
{
"Employee Number": 1388,
"English Competency": "No",
"Portfolio Lead": "y",
"Maths Competency": "yes"
},
{
"Employee Number": 1388,
"English Competency": "No",
"Portfolio Lead": "z",
"Maths Competency": "no"
}
];
******************UPDATE********************************
Although the code below is functioning correctly, it is only displaying the employee number in the employeeData
instead of the full data. Assistance is appreciated.
var leadsList = ['x','y','z']
function getcompetencyData(name) {
let filteredCompetency = data.filter(item => item[name] == "No");
console.log(filteredCompetency);
let leadData = [];
let employeeData = [];
leadsList.forEach(lead => {
filteredCompetency.forEach(competency => {
if (lead === competency["Portfolio Lead"]) {
leadData.push({ "Portfolio Lead": lead, "employeeData": employeeData.push(competency) })
}
})
});
console.log(leadData);
}
getcompetencyData('English Competency');
Please advise on any mistakes in the code. The stackblitz link for reference can be found below.