I am trying to create an HTML button that when clicked:
- Selects a random URL from an API
- Redirects to that selected URL
I have tried using an Array but as the list expands it no longer is efficient.
The code I have been using is a simple one:
<script type="text/javascript">
var urls = [
"/product/245170",
'/product/245166',
'/product/245189',
'/product/245108',
'/product/245041',
'/product/245098',
];
function discoverItems() {
var url = urls[Math.floor(Math.random()*urls.length)];
window.location = url; // redirect
}
</script>
I want it now to search from xyp.com/api/products and ask it to select a random url from there.
Help please!