Having trouble displaying an array in javascript -
hey guys i'm having trouble code. i'm trying loop through array whenever do, program show blank in firefox. appreciated. thanks!
<!doctype html> <html> <body> <p id="demo"></p> <script language="javascript" type="text/javascript"> var finished1 = ["firex";"enrique";0;0]; var finished2 = ["detector";"chris";0;0]; var finished3 = ["hpvv";"diana";0;0]; var info= new array ( ); info[0] = var info1 = ["firex"; "enrique"; 6; 20,000]; info[1] = var info2 = ["detector"; "chris"; 7; 35,000]; info[2] = var info3 = ["hpvv"; "diana"; 12; 10,000]; info[3] = var info4 = ["firex"; "enrique"; 4; 25,000]; info[4] = var info5 = ["detector"; "chris"; 3; 15,000]; info[5] = var info6 = ["hpvv"; "diana"; 3; 30,000]; info[6] = var info7 = ["firex"; "enrique"; 8; 10,000]; info[7] = var info8 = ["detector"; "chris"; 5; 20,000]; info[8] = var info9 = ["hpvv"; "diana"; 6; 15,000]; info[9] = var info10 = ["firex"; "enrique"; 5; 25,000]; info[10] = var info11 = ["detector"; "chris"; 6; 35,000]; info[11] = var info12 = ["hpvv"; "diana"; 7; 35,000]; info[12] = var info13 = ["firex"; "enrique"; 3 ; 40,000]; info[13] = var info14 = ["detector"; "chris"; 9 ; 10,000]; info[14] = var info15 = ["hpvv"; "diana"; 5 ; 15,000]; for(i = 0; < 15; i++) { if (info[0][0] = info[i][0]) { finished1[3] = info[0][2] + info[i][2]; finished1[3] = info[0][3] + info[i][3]; } if (info[1][0] = info[i][0]) { finished2[3] = info[1][2] + info[i][2]; finished2[3] = info[1][2] + info[i][3]; } if (info[2][0] = info[i][0]) { finished3[3] = info[2][2] + info[i][2]; finished3[3] = info[2][3] + info[i][3]; } } </script> </body> </html>
with program i'm trying take information in nested array. search , add third numbers , fourth numbers if array names match.
this trying achieve.
var finished1 = ["firex","enrique",0,0]; var finished2 = ["detector","chris",0,0]; var finished3 = ["hpvv","diana",0,0]; var info = []; info.push(["firex", "enrique", 6, 20000]); info.push(["detector", "chris", 7, 35000]); info.push(["hpvv", "diana", 12, 10000]); info.push(["firex", "enrique", 4, 25000]); info.push(["detector", "chris", 3, 15000]); info.push(["hpvv", "diana", 3, 30000]); info.push(["firex", "enrique", 8, 10000]); info.push(["detector", "chris", 5, 20000]); info.push(["hpvv", "diana", 6, 15000]); info.push(["firex", "enrique", 5, 25000]); info.push(["detector", "chris", 6, 35000]); info.push(["hpvv", "diana", 7, 35000]); info.push(["firex", "enrique", 3, 40000]); info.push(["detector", "chris", 9, 10000]); info.push(["hpvv", "diana", 5, 15000]); info.foreach(function(element, index, array) { if(array[0][0] === array[index][0]) { finished1[3] = array[0][2] + array[index][2]; finished1[3] = array[0][3] + array[index][3]; } else if(info[1][0] === info[index][0]) { finished2[3] = array[1][2] + array[index][2]; finished2[3] = array[1][2] + array[index][3]; } else if(info[2][0] === info[index][0]) { finished3[3] = array[2][2] + array[index][2]; finished3[3] = array[2][3] + array[index][3]; } }); console.log(finished1); console.log(finished2); console.log(finished3);
Comments
Post a Comment