How To Show 2D Array Data Using Javascript
In This Javascript Tutorial we will See How To Display A Multi-Dimensional Array Data Using For Loop In JS And Netbeans Editor .
Project Source Code:
<!DOCTYPE html>
<html>
<head>
<title>Javascript: display 2D array content</title>
<meta charset="windows-1252">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<script>
var ar = [
["A1","B1","C1","D1"],
["A2","B2","C2","D2"],
["A3","B3","C3","D3"],
["A4","B4","C4","D4"],
["A5","B5","C5","D5"]
], txt = "";
for(var i = 0; i < ar.length; i++){// lines
for(var k = 0; k < ar[i].length; k++){// columns
txt = txt + ar[i][k]+ " | ";
}
txt = txt + "<br>";
}
document.write(txt);
</script>
</body>
</html>
OUTPUT: