Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

121
Vistas
I have a collection of array in Js contains 1 to 30, on button click, i want to get the first shuffled value from it

I have a button which will call the function that contains the array and will shuffle it and return the first array after the click: Button:

<button onclick="show()">
    click
</button>

My Js:

<script>

const cars = [1,2,3,4,5,6,7,8]; 

</script>
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Check this out: Found it somewhere in geeksforgeeks credit to them.

<!DOCTYPE html>
<html>
 
<head>

</head>
 
<body>
    <button onclick="show()">
        click
    </button>
     
    <script>
 
        // Function to shuffle the array content
        function shuffleArray(array) {
            for (var i = array.length - 1; i > 0; i--) {
 
                // Generate random number
                var j = Math.floor(Math.random() * (i + 1));
 
                var temp = array[i];
                array[i] = array[j];
                array[j] = temp;
            }
 
            return array;
        }
 
        // Function to show the result
        function show() {
            var arr = [1, 2, 3, 4, 5, 6, 7]
            var arr1 = shuffleArray(arr)
 
            document.write("After shuffling: ", arr1[0])
        }
    </script>
</body>
 
</html>
about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda