Select a random string from an array
-
Possible Duplicate: http://stackoverflow.com/questions/4550505/javascript-getting-random-value-from-an-array Could someone help me on this topic? I've got this code. var textArray = [ 'song1.ogg', 'song2.ogg' ] audioElement.setAttribute('src', textArray); How can I randomly get one of those strings into my audio element? Would be glad if someone can help....
-
Answer:
var textArray = [ 'song1.ogg', 'song2.ogg' ]; var randomNumber = Math.floor(Math.random()*textArray.length); audioElement.setAttribute('src', textArray[randomNumber]);
Mausoleum at Stack Overflow Visit the source
Other answers
var randomIndex = Math.floor(Math.random() * textArray.length); var randomElement = textArray[randomIndex];
sberry
http://blog.mastykarz.nl/jquery-random-filter/ Here is a way you can do it with a JQuery Extension.
Joseph Shanak
Related Q & A:
- Is Guillou-Quisquater existentially unforgeable against adaptive message attack under a random oracle model?Best solution by Cryptography
- How to get nearest address of a random latitude and longitude?Best solution by Stack Overflow
- How to programatically select a item in list using c#?Best solution by Software Quality Assurance & Testing
- Can anyone tell me how to select a University in Aus or NZ to study MA or MS or MBA in Communication?Best solution by Yahoo! Answers
- How to search for a particular string in a text file using java?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.