I am trying to filter multiple arrays of Skills (they are coming from json file) (example below) and print out the candidate name + all skills
┌─────────┬───────────────────────┐
│ (index) │ Values │
├─────────┼───────────────────────┤
│ 0 │ 'angular' │
│ 1 │ 'css' │
│ 2 │ 'bootstrap' │
│ 3 │ 'react.js' │
│ 4 │ 'rxjs' │
│ 5 │ 'git' │
│ 6 │ 'java' │
│ 7 │ 'graphql' │
│ 8 │ 'node.js' │
│ 9 │ 'redux' │
│ 10 │ 'json' │
│ 11 │ 'html' │
│ 12 │ 'sql' │
│ 13 │ 'linux' │
│ 14 │ 'gatsby.js' │
│ 15 │ 'mongodb' │
│ 16 │ 'javascript' │
│ 17 │ 'php' │
│ 18 │ 'ionic' │
│ 19 │ 'amazon web services' │
└─────────┴───────────────────────┘
but instead of all skills I'm just getting single values (1 skill/1 line) and the output looks in console looks like this:
this guys knows javascript
this guys knows nodejs
this guys knows react
this guys knows javascript
But the goal is to have all skills in 1 line like this:
this guys knows javascript nodejs react
input.json
{
"stackIncluded": [
"nodejs",
"javascript"
]
}
Here is a code of the function that I've written, index.js
'use strict';
const curationInput = require('./curation-input.json');
const fileToCurate = require('./trlele.json');
async function curateStack() {
const stackIncluded = curationInput.stackIncluded;
fileToCurate.forEach(candidate => {
candidate.folder.forEach(folder => {
// get Arrays with all objects that including candidates skills
const allSkills = folder.skills;
// map Arrays with objects to Arrays with skills only
const values = allSkills.map(item => item.value);
// lowercase the values of skills
const lowercaseSkills = values.map(skill => skill.toLowerCase());
//console.table(lowercaseSkills)
lowercaseSkills.forEach(skillsArray => {
if (stackIncluded.includes(skillsArray)) {
console.log('this guys knows', skillsArray);
}
});
});
});
}
You need to change the last part of your script
let str = 'this guys knows '
lowercaseSkills.forEach(skillsArray => {
if (stackIncluded.includes(skillsArray)) {
str += skillsArray + ' ';
}
});
console.log(str);
another way
const skills = lowercaseSkills.filter(item => stackIncluded.includes(item));
console.log('this guys knows', skills.join(', ')]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.