Im trying to use a javascript function I have made to iterate over an array.My function looks like this and it works:
const shuffleAndPick = (array, amount) => {
return array.sort(() => 0.5 - Math.random()).slice(0, amount);
};
The thing is that I want it to iterate over an array and pick certain things like, ${image} ${name} etc.
Something like this (but only for the objects that my function randomly selects, as this example would iterate over the whole array):
{images.map((images) => (
<div className="key" key={images.id}>
<h3>{images.name}</h3>
<h3>{images.sanskritname}</h3>
<p>{images.description}</p>
<img src={images.image} alt={images.name} />
</div>
))}
Do I need to use my function with a map() for my purpose? And how would I write the correct syntax for that that if I want to write it in es6?
Thanks