How Can I Array into another Array?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-2















Guys can u help me? I wanna divide an array that is inside an array into another array.



For example I need to make it like this:



var car = [['mazda','red','at'],['honda','blue','at'],['toyota','green','mt']]
var mazda = //i want this array contain ['mazda','red','at']
var honda = //i want this array contain ['honda','blue','at']
var toyota = //i want this array contain ['toyota','green','mt']









share|improve this question































    -2















    Guys can u help me? I wanna divide an array that is inside an array into another array.



    For example I need to make it like this:



    var car = [['mazda','red','at'],['honda','blue','at'],['toyota','green','mt']]
    var mazda = //i want this array contain ['mazda','red','at']
    var honda = //i want this array contain ['honda','blue','at']
    var toyota = //i want this array contain ['toyota','green','mt']









    share|improve this question



























      -2












      -2








      -2








      Guys can u help me? I wanna divide an array that is inside an array into another array.



      For example I need to make it like this:



      var car = [['mazda','red','at'],['honda','blue','at'],['toyota','green','mt']]
      var mazda = //i want this array contain ['mazda','red','at']
      var honda = //i want this array contain ['honda','blue','at']
      var toyota = //i want this array contain ['toyota','green','mt']









      share|improve this question
















      Guys can u help me? I wanna divide an array that is inside an array into another array.



      For example I need to make it like this:



      var car = [['mazda','red','at'],['honda','blue','at'],['toyota','green','mt']]
      var mazda = //i want this array contain ['mazda','red','at']
      var honda = //i want this array contain ['honda','blue','at']
      var toyota = //i want this array contain ['toyota','green','mt']






      javascript arrays






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 4 at 13:45









      Shubham Jain

      680821




      680821










      asked Jan 4 at 0:26









      Ega JavierEga Javier

      22




      22
























          7 Answers
          7






          active

          oldest

          votes


















          3














          Arrays are indexed by number, a positive or null integer.



          So the first element is car[0], the second car[1], etc.



          That's how you would access the Mazda:



          var mazda = car[0]


          The elements inside the mazda array would similarly be accessed:



          var brand = mazda[0]


          However, you may want to consider using maps (objects in JavaScript) like:



          car = { mazda: { color: 'red', model: 'at' },
          honda: { color: 'blue', model: 'at' },
          toyota: { color: 'green', model: 'mt' } }


          Because then you can explicitly access that info:



          var mazda = car.mazda


          I think it's also less prone to mistakes.



          Of course, if you have have multiple mazdas, hondas, toyotas... then you will probably need an array at the top, still. Something like this:



          car = [
          { brand: 'mazda', color: 'red', model: 'at' },
          { brand: 'mazda', color: 'green', model: 'at' },
          { brand: 'mazda', color: 'blue', model: 'at' },
          ...
          ]


          You may also want to check into JSON which is very often used to transmit data in browsers. It's arrays, objects, values... If you are to program in JavaScript, you'll want to become a master at such.






          share|improve this answer


























          • i have a multiple mazda, so i need to make it like mazda = [['mazda','red','mt'],['mazda,'blue','at']]

            – Ega Javier
            Jan 4 at 1:04





















          1














          Well, the literal answer will be



          var mazda = car[0]



          and so forth. That said, this answer really isn't scalable... if you're learning Javascript, look into objects instead. Then you can do something like:



          var cars = { mazda: {color: 'red', otherThing: 'at'}, honda: {... so on ...}};
          console.log(cars.mazda.color); //will output 'red'





          share|improve this answer



















          • 1





            otherThing is probably model or something along those lines.

            – Code-Apprentice
            Jan 4 at 0:31











          • thankyou so much :)

            – Ega Javier
            Jan 4 at 0:46



















          1














          There are a lot of answers provided now. My opinion is that we can destructure the array and assign it to the variables like this:






          var car = [
          ['mazda', 'red', 'at'],
          ['honda', 'blue', 'at'],
          ['toyota', 'green', 'mt']
          ]

          let [
          mazda,
          honda,
          toyota
          ] = car
          console.log("Mazda: ", mazda)
          console.log("Honda: ", honda)
          console.log("Toyota: ", toyota)





          Hope it helps :)






          share|improve this answer
























          • this one gonna help me :) thankyou so much

            – Ega Javier
            Jan 4 at 0:46











          • @EgaJavier Glad I helped :)

            – Thinker
            Jan 4 at 0:49



















          1














          If you know the index of the outer array that you need, the other answers have provided the solution. If you don't know the index, and only know the first element of the inner array that you're looking for, then find is the tool you need:






          var car = [['mazda','red','at'],['honda','blue','at'],['toyota','green','mt']]

          var mazda = car.find(([make]) => make === 'mazda');
          var honda = car.find(([make]) => make === 'honda');
          var toyota = car.find(([make]) => make === 'toyota');

          console.log(mazda);
          console.log(honda);
          console.log(toyota);








          share|improve this answer
























          • thankyou so much :)

            – Ega Javier
            Jan 4 at 0:47



















          0














          I suggest that you read about JavaScript arrays. To help you get started, you can do one of your examples like this:



          var mazda = car[0];


          You should also learn about objects. Usually arrays should be used for a sequence of similar data. Here 'mazda', 'red', and 'at' are attributes of a car, but the order doesn't matter. 'mazda' is the brand, and 'red' is the color. These would make more sense to store in an object.






          share|improve this answer
























          • thankyou so much :)

            – Ega Javier
            Jan 4 at 0:46



















          0














          Use the index of the inner arrays when generating new ones.



          var mazda = car[0];
          var honda = car[1];
          var toyota = car[2];


          You can find a lot of good beginner information on Arrays, here.






          share|improve this answer































            0














            This is a basic case of multi-dimensional array. You might wanna learn and explore more on arrays.



            To solve your case you can solve as:



            var mazda = car[0];
            var honda = car[1];
            var toyota = car[2];


            This would have been better solved had you considered using objects. You can learn more about objects here.



            Since you have multiple mazdas structure of data you must consider is :



            var mazda = [{color: 'red', model: 'at'}, {color: 'green', model: 'at'}];





            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54031653%2fhow-can-i-array-into-another-array%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              7 Answers
              7






              active

              oldest

              votes








              7 Answers
              7






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              Arrays are indexed by number, a positive or null integer.



              So the first element is car[0], the second car[1], etc.



              That's how you would access the Mazda:



              var mazda = car[0]


              The elements inside the mazda array would similarly be accessed:



              var brand = mazda[0]


              However, you may want to consider using maps (objects in JavaScript) like:



              car = { mazda: { color: 'red', model: 'at' },
              honda: { color: 'blue', model: 'at' },
              toyota: { color: 'green', model: 'mt' } }


              Because then you can explicitly access that info:



              var mazda = car.mazda


              I think it's also less prone to mistakes.



              Of course, if you have have multiple mazdas, hondas, toyotas... then you will probably need an array at the top, still. Something like this:



              car = [
              { brand: 'mazda', color: 'red', model: 'at' },
              { brand: 'mazda', color: 'green', model: 'at' },
              { brand: 'mazda', color: 'blue', model: 'at' },
              ...
              ]


              You may also want to check into JSON which is very often used to transmit data in browsers. It's arrays, objects, values... If you are to program in JavaScript, you'll want to become a master at such.






              share|improve this answer


























              • i have a multiple mazda, so i need to make it like mazda = [['mazda','red','mt'],['mazda,'blue','at']]

                – Ega Javier
                Jan 4 at 1:04


















              3














              Arrays are indexed by number, a positive or null integer.



              So the first element is car[0], the second car[1], etc.



              That's how you would access the Mazda:



              var mazda = car[0]


              The elements inside the mazda array would similarly be accessed:



              var brand = mazda[0]


              However, you may want to consider using maps (objects in JavaScript) like:



              car = { mazda: { color: 'red', model: 'at' },
              honda: { color: 'blue', model: 'at' },
              toyota: { color: 'green', model: 'mt' } }


              Because then you can explicitly access that info:



              var mazda = car.mazda


              I think it's also less prone to mistakes.



              Of course, if you have have multiple mazdas, hondas, toyotas... then you will probably need an array at the top, still. Something like this:



              car = [
              { brand: 'mazda', color: 'red', model: 'at' },
              { brand: 'mazda', color: 'green', model: 'at' },
              { brand: 'mazda', color: 'blue', model: 'at' },
              ...
              ]


              You may also want to check into JSON which is very often used to transmit data in browsers. It's arrays, objects, values... If you are to program in JavaScript, you'll want to become a master at such.






              share|improve this answer


























              • i have a multiple mazda, so i need to make it like mazda = [['mazda','red','mt'],['mazda,'blue','at']]

                – Ega Javier
                Jan 4 at 1:04
















              3












              3








              3







              Arrays are indexed by number, a positive or null integer.



              So the first element is car[0], the second car[1], etc.



              That's how you would access the Mazda:



              var mazda = car[0]


              The elements inside the mazda array would similarly be accessed:



              var brand = mazda[0]


              However, you may want to consider using maps (objects in JavaScript) like:



              car = { mazda: { color: 'red', model: 'at' },
              honda: { color: 'blue', model: 'at' },
              toyota: { color: 'green', model: 'mt' } }


              Because then you can explicitly access that info:



              var mazda = car.mazda


              I think it's also less prone to mistakes.



              Of course, if you have have multiple mazdas, hondas, toyotas... then you will probably need an array at the top, still. Something like this:



              car = [
              { brand: 'mazda', color: 'red', model: 'at' },
              { brand: 'mazda', color: 'green', model: 'at' },
              { brand: 'mazda', color: 'blue', model: 'at' },
              ...
              ]


              You may also want to check into JSON which is very often used to transmit data in browsers. It's arrays, objects, values... If you are to program in JavaScript, you'll want to become a master at such.






              share|improve this answer















              Arrays are indexed by number, a positive or null integer.



              So the first element is car[0], the second car[1], etc.



              That's how you would access the Mazda:



              var mazda = car[0]


              The elements inside the mazda array would similarly be accessed:



              var brand = mazda[0]


              However, you may want to consider using maps (objects in JavaScript) like:



              car = { mazda: { color: 'red', model: 'at' },
              honda: { color: 'blue', model: 'at' },
              toyota: { color: 'green', model: 'mt' } }


              Because then you can explicitly access that info:



              var mazda = car.mazda


              I think it's also less prone to mistakes.



              Of course, if you have have multiple mazdas, hondas, toyotas... then you will probably need an array at the top, still. Something like this:



              car = [
              { brand: 'mazda', color: 'red', model: 'at' },
              { brand: 'mazda', color: 'green', model: 'at' },
              { brand: 'mazda', color: 'blue', model: 'at' },
              ...
              ]


              You may also want to check into JSON which is very often used to transmit data in browsers. It's arrays, objects, values... If you are to program in JavaScript, you'll want to become a master at such.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jan 4 at 1:26

























              answered Jan 4 at 0:30









              Alexis WilkeAlexis Wilke

              10.3k34281




              10.3k34281













              • i have a multiple mazda, so i need to make it like mazda = [['mazda','red','mt'],['mazda,'blue','at']]

                – Ega Javier
                Jan 4 at 1:04





















              • i have a multiple mazda, so i need to make it like mazda = [['mazda','red','mt'],['mazda,'blue','at']]

                – Ega Javier
                Jan 4 at 1:04



















              i have a multiple mazda, so i need to make it like mazda = [['mazda','red','mt'],['mazda,'blue','at']]

              – Ega Javier
              Jan 4 at 1:04







              i have a multiple mazda, so i need to make it like mazda = [['mazda','red','mt'],['mazda,'blue','at']]

              – Ega Javier
              Jan 4 at 1:04















              1














              Well, the literal answer will be



              var mazda = car[0]



              and so forth. That said, this answer really isn't scalable... if you're learning Javascript, look into objects instead. Then you can do something like:



              var cars = { mazda: {color: 'red', otherThing: 'at'}, honda: {... so on ...}};
              console.log(cars.mazda.color); //will output 'red'





              share|improve this answer



















              • 1





                otherThing is probably model or something along those lines.

                – Code-Apprentice
                Jan 4 at 0:31











              • thankyou so much :)

                – Ega Javier
                Jan 4 at 0:46
















              1














              Well, the literal answer will be



              var mazda = car[0]



              and so forth. That said, this answer really isn't scalable... if you're learning Javascript, look into objects instead. Then you can do something like:



              var cars = { mazda: {color: 'red', otherThing: 'at'}, honda: {... so on ...}};
              console.log(cars.mazda.color); //will output 'red'





              share|improve this answer



















              • 1





                otherThing is probably model or something along those lines.

                – Code-Apprentice
                Jan 4 at 0:31











              • thankyou so much :)

                – Ega Javier
                Jan 4 at 0:46














              1












              1








              1







              Well, the literal answer will be



              var mazda = car[0]



              and so forth. That said, this answer really isn't scalable... if you're learning Javascript, look into objects instead. Then you can do something like:



              var cars = { mazda: {color: 'red', otherThing: 'at'}, honda: {... so on ...}};
              console.log(cars.mazda.color); //will output 'red'





              share|improve this answer













              Well, the literal answer will be



              var mazda = car[0]



              and so forth. That said, this answer really isn't scalable... if you're learning Javascript, look into objects instead. Then you can do something like:



              var cars = { mazda: {color: 'red', otherThing: 'at'}, honda: {... so on ...}};
              console.log(cars.mazda.color); //will output 'red'






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 4 at 0:30









              Michael PrattMichael Pratt

              2,4771126




              2,4771126








              • 1





                otherThing is probably model or something along those lines.

                – Code-Apprentice
                Jan 4 at 0:31











              • thankyou so much :)

                – Ega Javier
                Jan 4 at 0:46














              • 1





                otherThing is probably model or something along those lines.

                – Code-Apprentice
                Jan 4 at 0:31











              • thankyou so much :)

                – Ega Javier
                Jan 4 at 0:46








              1




              1





              otherThing is probably model or something along those lines.

              – Code-Apprentice
              Jan 4 at 0:31





              otherThing is probably model or something along those lines.

              – Code-Apprentice
              Jan 4 at 0:31













              thankyou so much :)

              – Ega Javier
              Jan 4 at 0:46





              thankyou so much :)

              – Ega Javier
              Jan 4 at 0:46











              1














              There are a lot of answers provided now. My opinion is that we can destructure the array and assign it to the variables like this:






              var car = [
              ['mazda', 'red', 'at'],
              ['honda', 'blue', 'at'],
              ['toyota', 'green', 'mt']
              ]

              let [
              mazda,
              honda,
              toyota
              ] = car
              console.log("Mazda: ", mazda)
              console.log("Honda: ", honda)
              console.log("Toyota: ", toyota)





              Hope it helps :)






              share|improve this answer
























              • this one gonna help me :) thankyou so much

                – Ega Javier
                Jan 4 at 0:46











              • @EgaJavier Glad I helped :)

                – Thinker
                Jan 4 at 0:49
















              1














              There are a lot of answers provided now. My opinion is that we can destructure the array and assign it to the variables like this:






              var car = [
              ['mazda', 'red', 'at'],
              ['honda', 'blue', 'at'],
              ['toyota', 'green', 'mt']
              ]

              let [
              mazda,
              honda,
              toyota
              ] = car
              console.log("Mazda: ", mazda)
              console.log("Honda: ", honda)
              console.log("Toyota: ", toyota)





              Hope it helps :)






              share|improve this answer
























              • this one gonna help me :) thankyou so much

                – Ega Javier
                Jan 4 at 0:46











              • @EgaJavier Glad I helped :)

                – Thinker
                Jan 4 at 0:49














              1












              1








              1







              There are a lot of answers provided now. My opinion is that we can destructure the array and assign it to the variables like this:






              var car = [
              ['mazda', 'red', 'at'],
              ['honda', 'blue', 'at'],
              ['toyota', 'green', 'mt']
              ]

              let [
              mazda,
              honda,
              toyota
              ] = car
              console.log("Mazda: ", mazda)
              console.log("Honda: ", honda)
              console.log("Toyota: ", toyota)





              Hope it helps :)






              share|improve this answer













              There are a lot of answers provided now. My opinion is that we can destructure the array and assign it to the variables like this:






              var car = [
              ['mazda', 'red', 'at'],
              ['honda', 'blue', 'at'],
              ['toyota', 'green', 'mt']
              ]

              let [
              mazda,
              honda,
              toyota
              ] = car
              console.log("Mazda: ", mazda)
              console.log("Honda: ", honda)
              console.log("Toyota: ", toyota)





              Hope it helps :)






              var car = [
              ['mazda', 'red', 'at'],
              ['honda', 'blue', 'at'],
              ['toyota', 'green', 'mt']
              ]

              let [
              mazda,
              honda,
              toyota
              ] = car
              console.log("Mazda: ", mazda)
              console.log("Honda: ", honda)
              console.log("Toyota: ", toyota)





              var car = [
              ['mazda', 'red', 'at'],
              ['honda', 'blue', 'at'],
              ['toyota', 'green', 'mt']
              ]

              let [
              mazda,
              honda,
              toyota
              ] = car
              console.log("Mazda: ", mazda)
              console.log("Honda: ", honda)
              console.log("Toyota: ", toyota)






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 4 at 0:33









              ThinkerThinker

              2,254625




              2,254625













              • this one gonna help me :) thankyou so much

                – Ega Javier
                Jan 4 at 0:46











              • @EgaJavier Glad I helped :)

                – Thinker
                Jan 4 at 0:49



















              • this one gonna help me :) thankyou so much

                – Ega Javier
                Jan 4 at 0:46











              • @EgaJavier Glad I helped :)

                – Thinker
                Jan 4 at 0:49

















              this one gonna help me :) thankyou so much

              – Ega Javier
              Jan 4 at 0:46





              this one gonna help me :) thankyou so much

              – Ega Javier
              Jan 4 at 0:46













              @EgaJavier Glad I helped :)

              – Thinker
              Jan 4 at 0:49





              @EgaJavier Glad I helped :)

              – Thinker
              Jan 4 at 0:49











              1














              If you know the index of the outer array that you need, the other answers have provided the solution. If you don't know the index, and only know the first element of the inner array that you're looking for, then find is the tool you need:






              var car = [['mazda','red','at'],['honda','blue','at'],['toyota','green','mt']]

              var mazda = car.find(([make]) => make === 'mazda');
              var honda = car.find(([make]) => make === 'honda');
              var toyota = car.find(([make]) => make === 'toyota');

              console.log(mazda);
              console.log(honda);
              console.log(toyota);








              share|improve this answer
























              • thankyou so much :)

                – Ega Javier
                Jan 4 at 0:47
















              1














              If you know the index of the outer array that you need, the other answers have provided the solution. If you don't know the index, and only know the first element of the inner array that you're looking for, then find is the tool you need:






              var car = [['mazda','red','at'],['honda','blue','at'],['toyota','green','mt']]

              var mazda = car.find(([make]) => make === 'mazda');
              var honda = car.find(([make]) => make === 'honda');
              var toyota = car.find(([make]) => make === 'toyota');

              console.log(mazda);
              console.log(honda);
              console.log(toyota);








              share|improve this answer
























              • thankyou so much :)

                – Ega Javier
                Jan 4 at 0:47














              1












              1








              1







              If you know the index of the outer array that you need, the other answers have provided the solution. If you don't know the index, and only know the first element of the inner array that you're looking for, then find is the tool you need:






              var car = [['mazda','red','at'],['honda','blue','at'],['toyota','green','mt']]

              var mazda = car.find(([make]) => make === 'mazda');
              var honda = car.find(([make]) => make === 'honda');
              var toyota = car.find(([make]) => make === 'toyota');

              console.log(mazda);
              console.log(honda);
              console.log(toyota);








              share|improve this answer













              If you know the index of the outer array that you need, the other answers have provided the solution. If you don't know the index, and only know the first element of the inner array that you're looking for, then find is the tool you need:






              var car = [['mazda','red','at'],['honda','blue','at'],['toyota','green','mt']]

              var mazda = car.find(([make]) => make === 'mazda');
              var honda = car.find(([make]) => make === 'honda');
              var toyota = car.find(([make]) => make === 'toyota');

              console.log(mazda);
              console.log(honda);
              console.log(toyota);








              var car = [['mazda','red','at'],['honda','blue','at'],['toyota','green','mt']]

              var mazda = car.find(([make]) => make === 'mazda');
              var honda = car.find(([make]) => make === 'honda');
              var toyota = car.find(([make]) => make === 'toyota');

              console.log(mazda);
              console.log(honda);
              console.log(toyota);





              var car = [['mazda','red','at'],['honda','blue','at'],['toyota','green','mt']]

              var mazda = car.find(([make]) => make === 'mazda');
              var honda = car.find(([make]) => make === 'honda');
              var toyota = car.find(([make]) => make === 'toyota');

              console.log(mazda);
              console.log(honda);
              console.log(toyota);






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 4 at 0:38









              ic3b3rgic3b3rg

              10.9k42045




              10.9k42045













              • thankyou so much :)

                – Ega Javier
                Jan 4 at 0:47



















              • thankyou so much :)

                – Ega Javier
                Jan 4 at 0:47

















              thankyou so much :)

              – Ega Javier
              Jan 4 at 0:47





              thankyou so much :)

              – Ega Javier
              Jan 4 at 0:47











              0














              I suggest that you read about JavaScript arrays. To help you get started, you can do one of your examples like this:



              var mazda = car[0];


              You should also learn about objects. Usually arrays should be used for a sequence of similar data. Here 'mazda', 'red', and 'at' are attributes of a car, but the order doesn't matter. 'mazda' is the brand, and 'red' is the color. These would make more sense to store in an object.






              share|improve this answer
























              • thankyou so much :)

                – Ega Javier
                Jan 4 at 0:46
















              0














              I suggest that you read about JavaScript arrays. To help you get started, you can do one of your examples like this:



              var mazda = car[0];


              You should also learn about objects. Usually arrays should be used for a sequence of similar data. Here 'mazda', 'red', and 'at' are attributes of a car, but the order doesn't matter. 'mazda' is the brand, and 'red' is the color. These would make more sense to store in an object.






              share|improve this answer
























              • thankyou so much :)

                – Ega Javier
                Jan 4 at 0:46














              0












              0








              0







              I suggest that you read about JavaScript arrays. To help you get started, you can do one of your examples like this:



              var mazda = car[0];


              You should also learn about objects. Usually arrays should be used for a sequence of similar data. Here 'mazda', 'red', and 'at' are attributes of a car, but the order doesn't matter. 'mazda' is the brand, and 'red' is the color. These would make more sense to store in an object.






              share|improve this answer













              I suggest that you read about JavaScript arrays. To help you get started, you can do one of your examples like this:



              var mazda = car[0];


              You should also learn about objects. Usually arrays should be used for a sequence of similar data. Here 'mazda', 'red', and 'at' are attributes of a car, but the order doesn't matter. 'mazda' is the brand, and 'red' is the color. These would make more sense to store in an object.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 4 at 0:28









              Code-ApprenticeCode-Apprentice

              48.9k1492180




              48.9k1492180













              • thankyou so much :)

                – Ega Javier
                Jan 4 at 0:46



















              • thankyou so much :)

                – Ega Javier
                Jan 4 at 0:46

















              thankyou so much :)

              – Ega Javier
              Jan 4 at 0:46





              thankyou so much :)

              – Ega Javier
              Jan 4 at 0:46











              0














              Use the index of the inner arrays when generating new ones.



              var mazda = car[0];
              var honda = car[1];
              var toyota = car[2];


              You can find a lot of good beginner information on Arrays, here.






              share|improve this answer




























                0














                Use the index of the inner arrays when generating new ones.



                var mazda = car[0];
                var honda = car[1];
                var toyota = car[2];


                You can find a lot of good beginner information on Arrays, here.






                share|improve this answer


























                  0












                  0








                  0







                  Use the index of the inner arrays when generating new ones.



                  var mazda = car[0];
                  var honda = car[1];
                  var toyota = car[2];


                  You can find a lot of good beginner information on Arrays, here.






                  share|improve this answer













                  Use the index of the inner arrays when generating new ones.



                  var mazda = car[0];
                  var honda = car[1];
                  var toyota = car[2];


                  You can find a lot of good beginner information on Arrays, here.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 4 at 0:29









                  mdrichardson - MSFTmdrichardson - MSFT

                  1,2081111




                  1,2081111























                      0














                      This is a basic case of multi-dimensional array. You might wanna learn and explore more on arrays.



                      To solve your case you can solve as:



                      var mazda = car[0];
                      var honda = car[1];
                      var toyota = car[2];


                      This would have been better solved had you considered using objects. You can learn more about objects here.



                      Since you have multiple mazdas structure of data you must consider is :



                      var mazda = [{color: 'red', model: 'at'}, {color: 'green', model: 'at'}];





                      share|improve this answer




























                        0














                        This is a basic case of multi-dimensional array. You might wanna learn and explore more on arrays.



                        To solve your case you can solve as:



                        var mazda = car[0];
                        var honda = car[1];
                        var toyota = car[2];


                        This would have been better solved had you considered using objects. You can learn more about objects here.



                        Since you have multiple mazdas structure of data you must consider is :



                        var mazda = [{color: 'red', model: 'at'}, {color: 'green', model: 'at'}];





                        share|improve this answer


























                          0












                          0








                          0







                          This is a basic case of multi-dimensional array. You might wanna learn and explore more on arrays.



                          To solve your case you can solve as:



                          var mazda = car[0];
                          var honda = car[1];
                          var toyota = car[2];


                          This would have been better solved had you considered using objects. You can learn more about objects here.



                          Since you have multiple mazdas structure of data you must consider is :



                          var mazda = [{color: 'red', model: 'at'}, {color: 'green', model: 'at'}];





                          share|improve this answer













                          This is a basic case of multi-dimensional array. You might wanna learn and explore more on arrays.



                          To solve your case you can solve as:



                          var mazda = car[0];
                          var honda = car[1];
                          var toyota = car[2];


                          This would have been better solved had you considered using objects. You can learn more about objects here.



                          Since you have multiple mazdas structure of data you must consider is :



                          var mazda = [{color: 'red', model: 'at'}, {color: 'green', model: 'at'}];






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 4 at 13:14









                          Shubham JainShubham Jain

                          680821




                          680821






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54031653%2fhow-can-i-array-into-another-array%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Monofisismo

                              Angular Downloading a file using contenturl with Basic Authentication

                              Olmecas