1

I want to display project that filter on skills array, for example, if I select "HTML", show me, all project with "HTML" in the project array skills. And if I select two skills, display the project that have two skills.

I have this data for my project:

const data = [
  {
    id: "1",
    name: "project1",
    techno: ["JAVASCRIPT", "REACTJS"],
    imageUrl: "link",
  },
  {
    id: "2",
    name: "project2",
    techno: ["HTML", "CSS", "SASS"],
    imageUrl: "link",
  },
  {
    id: "3",
    name: "project3",
    techno: ["JAVASCRIPT", "HTML"],
    imageUrl: "link",
  }
];

And my arrayFilter

const filter = ["JAVASCRIPT", "HTML", "CSS"];

For the moment, I have this code :

 data
  .filter((filter) => filter.techno.includes(filter[0]))
  .map(({ id, ...otherProps }) => (
     <ProjectItem key={id} {...otherProps} />
     ))

Thank you for your help

1
  • What's the issue? Your code seems to be unfinished but you are on the good path, what is the problem? Commented Jun 29, 2020 at 11:57

1 Answer 1

2

You can use every

const data = [
    {
        id: '1',
        name: 'project1',
        techno: ['JAVASCRIPT', 'REACTJS'],
        imageUrl: 'link',
    },
    {
        id: '2',
        name: 'project2',
        techno: ['HTML', 'CSS', 'SASS'],
        imageUrl: 'link',
    },
    {
        id: '3',
        name: 'project3',
        techno: ['JAVASCRIPT', 'HTML', 'REACTJS'],
        imageUrl: 'link',
    },
];

const filter = ['JAVASCRIPT', 'REACTJS'];

const result = data.filter(d => filter.every(t => d.techno.includes(t)));

console.log(result);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.