+ 2
where this array concept can be used?
4 Respuestas
+ 3
Many many applications.. Here are some fun examples..
Var pagecontent=["content including dom or text or html or functions for home", "content for about","content for contact/location"];
function updatecont(n){
document.content.innerHtml = pagecontent[n];
}
Then for a menu you could do...
<a href="#content" onclick="updatecont(0)">Home</a> and so on...
Or...
Say u want a simple text to 1337 speak converter..
function simple1337(str){
var f = ["o","i","z","e","a","s","","t","b","g"];
var leetstr ="";
for(var i=0; i < str.length;i++){
var t = f.indexOf(str[i]);
if(t >= 0){
leetstr += String.fromCharCode(t+0x30);
} else {
leetstr += str[i];
}
}
return leetstr;
}
document.write(simple1337("oh.. You know.. Maybe for kewl thingz like this.."));
Which will output...
0h... Y0u kn0w... M4y83 f0r k3wl 7h1n92 l1k3 7h15..
+ 1
Storing data, applying functions to all of its elements, sorting the elements in regards to one of their properties, building more complex data structures... Also, strings are arrays of characters. Long story short, this is the most basic data structure and you will encounter it a lot.
0
When storing alot of data. Also useful when making games such as a chess game.
0
store a collection of data