|
|
səhifə | 4/6 | tarix | 26.10.2017 | ölçüsü | 1,37 Mb. | | #13375 |
| Arie de date
var arr = new Array(7);
arr[0] = "Steaua";
arr[1] = "Dinamo";
arr[2] = "Rapid";
arr[3] = "Poli Timisoara";
arr[4] = "UTA";
arr[5] = "U Cluj";
arr[6] = "Jiul Petrosani";
document.write(arr);
document.write("
Dupa sortare alfabetica,lista este:" + "
");
document.write(arr.sort());
document.write("
Pozitia a 6-a din arhiva este: " + arr[5] + "
");
var ultima = arr.pop();
document.write("
Ultima echipa din lista este: " + arr.pop());
arr.push("Farul","U Craiova","UTA","CSM Resita","Poli Iasi","FC Arges");
document.write("
Dupa actualizare,lista completa este: " + "
");
document.write(arr.sort());
document.write("
Lista contine: " + arr.length + " echipe");
document.write("
Lista inversata este: " + "
");
document.write(arr.reverse());
Arhiva
Introduceti datele:
var arhiva = new Array();
function Salveaza1()
{ var textnou=document.gerElementById("text1").value;
arhiva.push(document.getElementById("text1").value);
window.alert("textul salvat este: "+ textnou);
document.getElementById("text1").value = "";
}
function Afiseaza()
{ window.alert(arhiva); }
function Sorteaza()
{ window.alert(arhiva.sort()); }
function Inverseaza()
{ window.alert(arhiva.reverse()); }
function Sterge()
{ window.alert(arhiva.pop() + " a fost sters din lista"); }
Arie bidimensionala
var numere1= new Array()
numere1[0] = 5;
numere1[1] = 13;
numere1[2] = 17;
var numere2= new Array()
numere2[0] = 3.1475;
numere2[1] = 2.7283;
numere2[2] = 7.2357;
var texte = new Array()
texte[0] = "Primul rand de text";
texte[1] = "Al doilea rand de text";
texte[2] = "Al treilea rand de text";
var arie = new Array();
arie[0]=numere1;
arie[1]=numere2;
arie[2]=texte;
document.write(arie);
document.write("
A doua arie numerica este:
" + arie[1]);
Valorile alocate automat sunt:
var numere = new Array();
for (i=0;i<20;i++)
{ numere[i] = i; }
document.write(numere);
Selectie de date cu grep():
function grep(str)
{ var ar = new Array()
var arSub = 0
for (var i in this) {
if (typeof this[i] == "string" && this[i].indexOf(str) != -1)
{
ar[arSub] = this[i]
ar Sub++
}
}
return ar
}
Array.prototype.grep = grep
var numere = new Array("Ion","Mihai","Dan","Ion Ion","Vasile","Monica");
document.write(numere);
var selectie=numere.grep("Ion");
document.write("
"+selectie);
document.write("
" + numere.grep("Mihai"));
document.write("
" + numere.grep("on"));
document.write("
nr. date selectate= " + numere.grep("on").length);
Obiectul String (exemple)
var text1 = "Text exemplificativ";
document.write(text1.big());
document.write("
" + text1.fontsize(14));
document.write("
" + text1.fontcolor("red"));
document.write("
+ text1.toUpperCase());
document.write("
+ text1.match("exe"));
for (i=0;i<19;i++)
{ document.write("
" + text1.charAt(i)); }
Obiectul String (exemple)
var text1 = "UNU";
var text2 = "DOI";
var text3 = "TREI";
var text4 = new String();
document.write(text4.concat(text1.italics(),text2,text3.fontsize(14)));
document.write("
"+text4.concat(text3.small(),text2.strike(),text1));
Dostları ilə paylaş: |
|
|