Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • create object and object's combination

    • 2
    • 1
    • 1
    • 2
    • 0
    • 0
    • 0
    • 548
    Answer it

    I need help in javascript friends I have 3 javascript array.

    var color = ["red", "yellow", "blue"]; var size = ["xl", "xxl", "xxxl"]; var style = ["cotton", "silk", "jins"];

    and i want string like bellow line using javascript or jquery.

    lbl-01 = "red - xl - cotton"

    lbl-02 = "red - xl - silk"

    lbl-03 = "red - xl - jins"

    lbl-04 = "red - xxl - cotton"

    lbl-05 = "red - xxl - silk"

    lbl-06 = "red - xxl - jins"

    lbl-07 = "red - xxxl - cotton"

    lbl-08 = "red - xxxl - silk"

    lbl-09 = "red - xxxl - jins"

    lbl-10 = "yellow - xl - cotton"

    lbl-11 = "yellow - xl - silk"

    lbl-12 = "yellow - xl - jins"

    lbl-13 = "yellow - xxl - cotton"

    lbl-14 = "yellow - xxl - silk"

    lbl-15 = "yellow - xxl - jins"

    lbl-16 = "yellow - xxxl - cotton"

    lbl-17 = "yellow - xxxl - silk"

    lbl-18 = "yellow - xxxl - jins"

    lbl-19 = "blue - xl - cotton"

    lbl-20 = "blue - xl - silk"

    lbl-21 = "blue - xl - jins"

    lbl-22 = "blue - xxl - cotton"

    lbl-23 = "blue - xxl - silk"

    lbl-24 = "blue - xxl - jins"

    lbl-25 = "blue - xxxl - cotton"

    lbl-26 = "blue - xxxl - silk"

    lbl-27 = "blue - xxxl - jins"

    pls help in this task

 2 Answer(s)

  • This is the solution to the above problem....

      <html>
      <head>
      <script>
    var color = ["red", "yellow", "blue"];
    var size = ["xl", "xxl", "xxxl"]; 
    var style = ["cotton", "silk", "jins"];
    var i=0;
    var j=0;
    var k=0;
    var counter = 0;
    
          while (i<color.length) 
        {
            console.log("*****"+color[i]+"********");
                    while(j<size.length)
                    {
    
                            while(k<style.length)
                            {
                                console.log("lbl- "+counter+"= "+" "+color[i]+" "+size[j]+" "+style[k]+" ");
                                k++;
                                counter++;
                            }
                        k=0;
                        j++;
                    }
            k=0;
            j=0;
            i++;
        }
    
     </script>
     </head>
     </html>
    

    Thanks For any queries leave the comment..

  • Try this jQuery function..

    <script type="text/javascript">
    
    var color = ["red", "yellow", "blue"];
    var size = ["xl", "xxl", "xxxl"];
    var style = ["cotton", "silk", "jins"];
    
    function GetVal() {
        var arr = new Array();
        $.each(color, function (i, colorVal) {
            $.each(size, function (j, sizeVal) {
                $.each(style, function (k, styleVal) {
                    arr.push(colorVal + " - " + sizeVal + " - " + styleVal);
                });
            });
       });
       return arr;
    }
    </script>
    

    This will return an array of string as per your requirement.

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: