I'm trying to randomly display items from an array and I've been able to get it so that one item displays at random, now I want it to display a random number of items based on a number that I put in e.g when I input 2 I want 2 random items, when I input 5 I want 5 random items, etc... How'd I go by this?
Code
const counter = 2; // Number of items I want to show
const Accounts = accountsData.sort(() => Math.random() - Math.random()).find(() => true); // This displays only one random item
<div className="text-area">
{"Email: " + Accounts.email + " | Password: " + Accounts.password + " | Country: " + Accounts.country + " | Current Plan: " + Accounts.currentPlan + " | Has UHD: " + Accounts.hasUHD + " | Max Streams: " + Accounts.maxStreams + " | Payment Method: " + Accounts.paymentMethod}
</div>
const fetchRandomValues = (arr) => (counter) =>
[...Array(counter)].map(() => arr[Math.floor(Math.random() * arr.length)]);
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const values = fetchRandomValues(arr)(2);
console.log(values)