Sunday, October 23, 2022

Random array items generator

Generate n random posts from array:

const n = 4; // n random posts generator
const randomPosts = (function getRandomInt(max) {
return Math.floor(Math.random() * max);
})(posts.length - n);

{posts.slice(randomPosts, randomPosts + n).map(...}

//

No comments:

Post a Comment