array [1) = 55;
array [2] = 100;
array [3] = 150;
en un bucle, como los voy sumando
x = array [1]; ...o sea x = 55
x = array [1+2]; ...o sea x = 55 + 100
x = array [1+2+3]; o sea x = 55 + 100 + 150
cual es la instruccion??????
| ||||
|
Código:
misvalores=new Array("100","50","20");
sumar=function(valor1,valor2){
v1=Number(misvalores[valor1]);
v2=Number(misvalores[valor2]);
trace(v1+v2);
}
sumar(1,0);
Última edición por ¬...; 23/06/2004 a las 18:00 |
| ||||
| myarray = new Array("100","200","300","400", "500"); function sumar(myarray){ var total =0; for(i=0;i<=myarray.length;i++){ total+=myarray[i]; } } trace("Total del contenido del arreglo " + sumar(myarray)); No lo he probado pero no le veo el pero. Salu2
__________________ http://www.flotdesign.dk/ Última edición por pulento; 24/06/2004 a las 01:50 |
| ||||
| Gracias, me han ayudado BASTANTE myarray = new Array(100, 200, 300, 400, 500); trace(myarray.toString()); var total; function sumar(myarray) { //var total = 0; for (i=0; i<myarray.length; i++) { total += myarray[i]; trace('total '+i+' :'+total); } } sumar(myarray); trace("Total del contenido del arreglo "+ total); |