Javascript Search Item Position In A MultiDimensional Array

How To Get Value Position In A 2D Array Using Javascript 

Javascript Search Item Position In A MultiDimensional Array


In This Javascript Tutorial we will See How To Search Data In A Multi-Dimensional And Get The Data Positions In The 2D Array Using For Loop Using JS And Netbeans Editor .


Project Source Code:

    <!DOCTYPE html>
<html>
    <head>
        <title>Javascript: search in multidimensional array</title>
        <meta charset="windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        
        <p id="txt"></p>
        
        <script>
            
            var ar = [
                       ["A1","B1","B5","D1"],//0
                       ["A2","B2","C2","B5"],//1
                       ["B5","B3","B5","D3"],//2
                       ["A4","B4","C4","B5"],
                       ["A5","B5","C5","D5"]
            ], txt = document.getElementById("txt"), data = "";
            
            for(var i = 0; i < ar.length; i++){// lines
                
                for(var j = 0; j < ar[i].length; j++){ // columns
                    data = data + ar[i][j]+" , ";
                    if(ar[i][j] === "B5"){
                        console.log("POSITION[ " + i + " , " + j +" ]")
                    }
                    
                }
                data = data + "<br>";
            }
            txt.innerHTML = data;
           
         </script>   
        
    </body>
</html>




OUTPUT:



search in multidimensional array In JS

Share this

Related Posts

Previous
Next Post »