Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
Tengo una colección de matriz en Js que contiene de 1 a 30, al hacer clic en el botón, quiero obtener el primer valor aleatorio de ella

Tengo un botón que llamará a la función que contiene la matriz y la barajará y devolverá la primera matriz después del clic: Botón:

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

Mis Js:

 <script> const cars = [1,2,3,4,5,6,7,8]; </script>
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Mira esto: lo encontré en algún lugar en el crédito de geeksforgeeks para ellos.

 <!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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!