OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

why i am getting an error that courses.foreach is not a function [closed]

  • Thread starter Thread starter Pushpendra Rajput
  • Start date Start date
P

Pushpendra Rajput

Guest
Code:
import Card from "./Card";

function Cards(props) {
  let courses = props.coarses;

  const getCoarses = () => {
    let AllCourses = [];
    Object.values(
      courses.foreach((array) => {
        array.foreach((coursedata) => {
          AllCourses.push(coursedata);
        });
      }),
    );
    return AllCourses;
  };

  return (
    <div>
      {getCoarses().map((course) => (
        <Card key={course.id} course={course}></Card>
      ))}
    </div>
  );
}
export default Cards;

I am working with an api and i get data from api

<pre class="lang-jsx prettyprint-override"><code>import Card from "./Card";

function Cards(props) {
let courses = props.coarses;

const getCoarses = () => {
let AllCourses = [];
Object.values(
courses.foreach((array) => {
array.foreach((coursedata) => {
AllCourses.push(coursedata);
});
}),
);
return AllCourses;
};

return (
<div>
{getCoarses().map((course) => (
<Card key={course.id} course={course}></Card>
))}
</div>
);
}
export default Cards;
</code></pre>
<p>I am working with an api and i get data from api</p>
 
Top