Originariamente inviato da fcaldera
notizie.push()
ti permette di accodare un valore in un array
codice:
<html>
<head>
<title>Notizie in Js</title>
<script language="JavaScript" type="text/javascript">
<!--
//-->
notizie = new Array()
notizie[0] = new Array("data","societa","Roma","titolo","testo breve","url")
notizie[1] = new Array("data1","societa1","Roma","titolo1","testo breve1","url1")
function leggiNews (){
for (i=0;i<notizie.length;i++) {
document.write("<div>"+notizie[i][0]+"-"+notizie[i][1]+"-"+notizie[i][2]+"</div>")
document.write(""+notizie[i][3]+"</div>")
document.write("<div>[i]"+notizie[4]+"</div>
")
}
}
function aggiungiNews(data,societa,citta,titolo,testoBreve,url){
nuova = new Array (data,societa,citta,titolo,testoBreve,url)
notizie.push(nuova)
leggiNews()
}
</script>
</head>
<script language="JavaScript" type="text/javascript">
<!--
leggiNews()
//-->
</script>
<input type="button" value="inserisci" onClick="aggiungiNews('data2','societa2','roma','titolo2','Ciao a tutti','url2')">
</body>
</html>
Fatto con .push()
Ma come faccio ad aggiornare l'array in modo definitivo? Cioè a "scrivere" fisicamente in coda agli elementi già presenti?
Spero che sia chiaro come l'ho posta...
(o so, so' de coccio, ma non ci fate caso.....
)