How to divide the information of an array and send it to another array? [duplicate]





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







0
















This question already has an answer here:




  • Group by element in array by keyword

    3 answers




I have this array in Javascript:



cars = [
{color: red, type: sedan, name: ferrari},
{color: blue, type: sedan, name: ferrari},
{color: yellow, type: sedan, name: ferrari},
{color: red, type: coupe, name: toyota},
{color: red, type: sedan, name: toyota}
]


What I am trying to do is create a multidimensional array where I have the information of the first array but it looks like this:



I want to separate ferraris cars from Toyota



carsseparated[0] = [
{color: red, type: sedan, name: ferrari},
{color: blue, type: sedan, name: ferrari},
{color: yellow, type: sedan, name: ferrari}
]

carsseparated[1] = [
{color: red, type: coupe, name: toyota},
{color: red, type: sedan, name: toyota}
]


this is what I have been coding



$scope.carsseparated= ;
var cont = 0;
$.each($scope.cars, function (index,value) {
$scope.carsseparated[cont] = [value.color, value.type, value.name]
cont = cont+1;
}









share|improve this question















marked as duplicate by Ori Drori arrays
Users with the  arrays badge can single-handedly close arrays questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 15:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

























    0
















    This question already has an answer here:




    • Group by element in array by keyword

      3 answers




    I have this array in Javascript:



    cars = [
    {color: red, type: sedan, name: ferrari},
    {color: blue, type: sedan, name: ferrari},
    {color: yellow, type: sedan, name: ferrari},
    {color: red, type: coupe, name: toyota},
    {color: red, type: sedan, name: toyota}
    ]


    What I am trying to do is create a multidimensional array where I have the information of the first array but it looks like this:



    I want to separate ferraris cars from Toyota



    carsseparated[0] = [
    {color: red, type: sedan, name: ferrari},
    {color: blue, type: sedan, name: ferrari},
    {color: yellow, type: sedan, name: ferrari}
    ]

    carsseparated[1] = [
    {color: red, type: coupe, name: toyota},
    {color: red, type: sedan, name: toyota}
    ]


    this is what I have been coding



    $scope.carsseparated= ;
    var cont = 0;
    $.each($scope.cars, function (index,value) {
    $scope.carsseparated[cont] = [value.color, value.type, value.name]
    cont = cont+1;
    }









    share|improve this question















    marked as duplicate by Ori Drori arrays
    Users with the  arrays badge can single-handedly close arrays questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 23 '18 at 15:24


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      0












      0








      0









      This question already has an answer here:




      • Group by element in array by keyword

        3 answers




      I have this array in Javascript:



      cars = [
      {color: red, type: sedan, name: ferrari},
      {color: blue, type: sedan, name: ferrari},
      {color: yellow, type: sedan, name: ferrari},
      {color: red, type: coupe, name: toyota},
      {color: red, type: sedan, name: toyota}
      ]


      What I am trying to do is create a multidimensional array where I have the information of the first array but it looks like this:



      I want to separate ferraris cars from Toyota



      carsseparated[0] = [
      {color: red, type: sedan, name: ferrari},
      {color: blue, type: sedan, name: ferrari},
      {color: yellow, type: sedan, name: ferrari}
      ]

      carsseparated[1] = [
      {color: red, type: coupe, name: toyota},
      {color: red, type: sedan, name: toyota}
      ]


      this is what I have been coding



      $scope.carsseparated= ;
      var cont = 0;
      $.each($scope.cars, function (index,value) {
      $scope.carsseparated[cont] = [value.color, value.type, value.name]
      cont = cont+1;
      }









      share|improve this question

















      This question already has an answer here:




      • Group by element in array by keyword

        3 answers




      I have this array in Javascript:



      cars = [
      {color: red, type: sedan, name: ferrari},
      {color: blue, type: sedan, name: ferrari},
      {color: yellow, type: sedan, name: ferrari},
      {color: red, type: coupe, name: toyota},
      {color: red, type: sedan, name: toyota}
      ]


      What I am trying to do is create a multidimensional array where I have the information of the first array but it looks like this:



      I want to separate ferraris cars from Toyota



      carsseparated[0] = [
      {color: red, type: sedan, name: ferrari},
      {color: blue, type: sedan, name: ferrari},
      {color: yellow, type: sedan, name: ferrari}
      ]

      carsseparated[1] = [
      {color: red, type: coupe, name: toyota},
      {color: red, type: sedan, name: toyota}
      ]


      this is what I have been coding



      $scope.carsseparated= ;
      var cont = 0;
      $.each($scope.cars, function (index,value) {
      $scope.carsseparated[cont] = [value.color, value.type, value.name]
      cont = cont+1;
      }




      This question already has an answer here:




      • Group by element in array by keyword

        3 answers








      javascript jquery arrays angularjs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 17:41









      georgeawg

      34.7k115470




      34.7k115470










      asked Nov 23 '18 at 15:21









      TalkedTalked

      205




      205




      marked as duplicate by Ori Drori arrays
      Users with the  arrays badge can single-handedly close arrays questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 23 '18 at 15:24


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Ori Drori arrays
      Users with the  arrays badge can single-handedly close arrays questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 23 '18 at 15:24


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          1

















          let cars = [{color: "red", type: "sedan", name: "ferrari"}, {color: "blue", type: "sedan", name: "ferrari"}, {color: "yellow", type: "sedan", name: "ferrari"}, {color: "red", type: "coupe", name: "toyota"},
          {color: "red", type: "sedan", name: "toyota"}];

          let car1 = cars.filter(val => val.name === 'ferrari');
          let car2 = cars.filter(val => val.name === 'toyota');
          console.log(car1)








          share|improve this answer
























          • yes, I guess that may work, but I'm trying to make it dynamic, what I want to say is that, I do not want to do this: val.name === 'ferrari' thanks for answering.

            – Talked
            Nov 23 '18 at 15:42


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1

















          let cars = [{color: "red", type: "sedan", name: "ferrari"}, {color: "blue", type: "sedan", name: "ferrari"}, {color: "yellow", type: "sedan", name: "ferrari"}, {color: "red", type: "coupe", name: "toyota"},
          {color: "red", type: "sedan", name: "toyota"}];

          let car1 = cars.filter(val => val.name === 'ferrari');
          let car2 = cars.filter(val => val.name === 'toyota');
          console.log(car1)








          share|improve this answer
























          • yes, I guess that may work, but I'm trying to make it dynamic, what I want to say is that, I do not want to do this: val.name === 'ferrari' thanks for answering.

            – Talked
            Nov 23 '18 at 15:42
















          1

















          let cars = [{color: "red", type: "sedan", name: "ferrari"}, {color: "blue", type: "sedan", name: "ferrari"}, {color: "yellow", type: "sedan", name: "ferrari"}, {color: "red", type: "coupe", name: "toyota"},
          {color: "red", type: "sedan", name: "toyota"}];

          let car1 = cars.filter(val => val.name === 'ferrari');
          let car2 = cars.filter(val => val.name === 'toyota');
          console.log(car1)








          share|improve this answer
























          • yes, I guess that may work, but I'm trying to make it dynamic, what I want to say is that, I do not want to do this: val.name === 'ferrari' thanks for answering.

            – Talked
            Nov 23 '18 at 15:42














          1












          1








          1










          let cars = [{color: "red", type: "sedan", name: "ferrari"}, {color: "blue", type: "sedan", name: "ferrari"}, {color: "yellow", type: "sedan", name: "ferrari"}, {color: "red", type: "coupe", name: "toyota"},
          {color: "red", type: "sedan", name: "toyota"}];

          let car1 = cars.filter(val => val.name === 'ferrari');
          let car2 = cars.filter(val => val.name === 'toyota');
          console.log(car1)








          share|improve this answer
















          let cars = [{color: "red", type: "sedan", name: "ferrari"}, {color: "blue", type: "sedan", name: "ferrari"}, {color: "yellow", type: "sedan", name: "ferrari"}, {color: "red", type: "coupe", name: "toyota"},
          {color: "red", type: "sedan", name: "toyota"}];

          let car1 = cars.filter(val => val.name === 'ferrari');
          let car2 = cars.filter(val => val.name === 'toyota');
          console.log(car1)








          let cars = [{color: "red", type: "sedan", name: "ferrari"}, {color: "blue", type: "sedan", name: "ferrari"}, {color: "yellow", type: "sedan", name: "ferrari"}, {color: "red", type: "coupe", name: "toyota"},
          {color: "red", type: "sedan", name: "toyota"}];

          let car1 = cars.filter(val => val.name === 'ferrari');
          let car2 = cars.filter(val => val.name === 'toyota');
          console.log(car1)





          let cars = [{color: "red", type: "sedan", name: "ferrari"}, {color: "blue", type: "sedan", name: "ferrari"}, {color: "yellow", type: "sedan", name: "ferrari"}, {color: "red", type: "coupe", name: "toyota"},
          {color: "red", type: "sedan", name: "toyota"}];

          let car1 = cars.filter(val => val.name === 'ferrari');
          let car2 = cars.filter(val => val.name === 'toyota');
          console.log(car1)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 15:28









          raviravi

          25828




          25828













          • yes, I guess that may work, but I'm trying to make it dynamic, what I want to say is that, I do not want to do this: val.name === 'ferrari' thanks for answering.

            – Talked
            Nov 23 '18 at 15:42



















          • yes, I guess that may work, but I'm trying to make it dynamic, what I want to say is that, I do not want to do this: val.name === 'ferrari' thanks for answering.

            – Talked
            Nov 23 '18 at 15:42

















          yes, I guess that may work, but I'm trying to make it dynamic, what I want to say is that, I do not want to do this: val.name === 'ferrari' thanks for answering.

          – Talked
          Nov 23 '18 at 15:42





          yes, I guess that may work, but I'm trying to make it dynamic, what I want to say is that, I do not want to do this: val.name === 'ferrari' thanks for answering.

          – Talked
          Nov 23 '18 at 15:42





          Popular posts from this blog

          If I really need a card on my start hand, how many mulligans make sense? [duplicate]

          Alcedinidae

          Can an atomic nucleus contain both particles and antiparticles? [duplicate]