I just wonder how to pick random URLs to performed an axios post request.
I have three servers I want to pick randomly from
let one = "http://127.0.0.1:8000/middle/server_js/" let two = "http://127.0.0.1:8001/middle/server_js/" let three = "http://127.0.0.1:8002/middle/server_js/"
currently is using only one:
let req = await axios.post("http://127.0.0.1:8000/middle/server_js/", body, {
I just want to choose random port from
Advertisement
Answer
Example of a solution via an array
// Defining an array var arr = ['adress1', 'adress2', 'adress3']; // Getting a random array key var rand = Math.floor(Math.random() * arr.length); alert(arr[rand]); // "adress2" for example