效果图:
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>随机从数组中取某一个值</title> </head> <body> </body> <script> var items = ['1','2','3','4']; var vaule = items[Math.floor(Math.random()*items.length)]; console.log(vaule,'随机从数组中取到的某一个值'); </script> </html>