Click here to Skip to main content
15,867,942 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to show each group with your stagiaires But it doesn't show with this attempt 


JavaScript
<pre>import React from "react";
import Stagiaires from "./components/Stagiaires";
function App() {
  const stagiaire = [
    {
      id: 1,
      title: "group1",
      stagiaires: [
        { id: 1, Name: "Massimo", Prenom: "Morson", Moyenne: "10" },
        { id: 2, Name: "Julian", Prenom: "Andreu", Moyenne: "14" },
        { id: 3, Name: "Sarette", Prenom: "Rulten", Moyenne: "17" },
        { id: 4, Name: "Marian", Prenom: "Billingsly", Moyenne: "9" },
      ],
    },
    {
      id: 2,
      title: "group2",
      stagiaires: [
        { id: 1, Name: "Katusha", Prenom: "Pirie", Moyenne: "17" },
        { id: 2, Name: "Ettore", Prenom: "Duck", Moyenne: "19" },
        { id: 3, Name: "Stefania", Prenom: "Lathee", Moyenne: "10" },
        { id: 4, Name: "Joella", Prenom: "Plevey", Moyenne: "8" },
      ],
    },
    {
      id: 3,
      title: "group3",
      stagiaires: [
        { id: 1, Name: "Westley", Prenom: "Dawdary", Moyenne: "13" },
        { id: 2, Name: "Kori", Prenom: "Munden", Moyenne: "12" },
        { id: 3, Name: "Woodrow", Prenom: "Simone", Moyenne: "16" },
        { id: 4, Name: "Joleen", Prenom: "Kupka", Moyenne: "15" },
      ],
    },
  ];
  return (
    <div className="App">
      {stagiaire.map((group) => {
        <table>
          <thead>
            <tr>
              <th key={group.id}>{group.title}</th>;
            </tr>
          </thead>
          <tbody>
            {stagiaire.map((group) => {
              <td key={group.stagiaires.id}>
                <Stagiaires stagiaire={group.stagiaires} />
              </td>;
            })}
          </tbody>
        </table>;
      })}
    </div>
  );
}

export default App;



What I have tried:

I want to show each group with your stagiaires


HTML
<div className="App">
      {stagiaire.map((group) => {
        <table>
          <thead>
            <tr>
              <th key={group.id}>{group.title}</th>;
            </tr>
          </thead>
          <tbody>
            {stagiaire.map((group) => {
              <td key={group.stagiaires.id}>
                <Stagiaires stagiaire={group.stagiaires} />
              </td>;
            })}
          </tbody>
        </table>;
      })}
    </div>
Posted
Updated 28-Dec-22 17:39pm
v3

1 solution

Hi,

The .map function is only available on array and your constant stagiaire is not an array and also the title values should be in quotes. You need to correct it like that:

const stagiaire = [
  {
    id: 1,
    title: "group1",
    stagiaires: [
      { Name: "Massimo", Prenom: "Morson", Moyenne: "10" },
      { Name: "Julian", Prenom: "Andreu", Moyenne: "14" },
      { Name: "Sarette", Prenom: "Rulten", Moyenne: "17" },
      { Name: "Marian", Prenom: "Billingsly", Moyenne: "9" },
    ],
  },
  {
    id: 2,
    title: "group2",
    stagiaires: [
      { Name: "Katusha", Prenom: "Pirie", Moyenne: "17" },
      { Name: "Ettore", Prenom: "Duck", Moyenne: "19" },
      { Name: "Stefania", Prenom: "Lathee", Moyenne: "10" },
      { Name: "Joella", Prenom: "Plevey", Moyenne: "8" },
    ],
  },
  {
    id: 3,
    title: "group3",
    stagiaires: [
      { Name: "Westley", Prenom: "Dawdary", Moyenne: "13" },
      { Name: "Kori", Prenom: "Munden", Moyenne: "12" },
      { Name: "Woodrow", Prenom: "Simone", Moyenne: "16" },
      { Name: "Joleen", Prenom: "Kupka", Moyenne: "15" },
    ],
  },
];
 
Share this answer
 
Comments
wiam leo 28-Dec-22 23:36pm    
I changed that but I have an error in map (the path is correct I don't why map doesn't work )
the error*****
Array.prototype.map() expects a return value from arrow function

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900