How do I split and Array into two parts based on type- Angular JS












0















I am trying to split an array into 2 types based on type: Buyer or Supplier. If you look at the last snippet, there is an array called newCompanies where there are company names with the type of company.



I am trying to get that company array data from local storage and I want to split them into 2 arrays so that I can have 2 types of listboxes. One is the Buyer listbpx and the other is supplier listbox.



Thanks in advance



var companies = JSON.parse(localStorage.getItem("newCompany"));

var splitted = companies.reduce(function(obj, item) {
if (obj[item.type] == null) {
obj[item.type] = ;
}
obj[item.type].push(item);
return obj;
}, {});

splitted.buyer;
splitted.supplier;
$scope.companies.push(splitted.supplier);

$scope.companies.push(splitted.buyer);


<div class="form-group">
<label class="control-label col-sm-2">Company</label>
<div class="col-sm-10" ng-class="{ 'has-error' : addForm.addCompany.$invalid && !addForm.addCompany.$pristine }">
<select class="form-control" name="addCompany"
placeholder="Select Company"
ng-options="company for company in companies"
ng-model="newUser.company" ng-required="true">
</select>
<span class="help-block" ng-show="addForm.addCompany.$invalid && !addForm.addCompany.$pristine">
Your Company is required.
</span>
</div>
</div>




var newCompany = [{
name: "Huawei", // -->COMPANY NAME
email: "Drath@yahoo.com",
phone: "123-123-1234",
owner: "Drath",
type: "buyer"
},
{
name: "Asus", // -->COMPANY NAME
email: "Vadar@yahoo.com",
phone: "999-123-8888",
owner: "Vadar",
type: "supplier"
},
{
name: "Acer", // -->COMPANY NAME
email: "Radal@yahoo.com",
phone: "676-989-8888",
owner: "Randall",
type: "supplier"
}
];
window.localStorage.setItem("newCompany", JSON.stringify(newCompany));











share|improve this question





























    0















    I am trying to split an array into 2 types based on type: Buyer or Supplier. If you look at the last snippet, there is an array called newCompanies where there are company names with the type of company.



    I am trying to get that company array data from local storage and I want to split them into 2 arrays so that I can have 2 types of listboxes. One is the Buyer listbpx and the other is supplier listbox.



    Thanks in advance



    var companies = JSON.parse(localStorage.getItem("newCompany"));

    var splitted = companies.reduce(function(obj, item) {
    if (obj[item.type] == null) {
    obj[item.type] = ;
    }
    obj[item.type].push(item);
    return obj;
    }, {});

    splitted.buyer;
    splitted.supplier;
    $scope.companies.push(splitted.supplier);

    $scope.companies.push(splitted.buyer);


    <div class="form-group">
    <label class="control-label col-sm-2">Company</label>
    <div class="col-sm-10" ng-class="{ 'has-error' : addForm.addCompany.$invalid && !addForm.addCompany.$pristine }">
    <select class="form-control" name="addCompany"
    placeholder="Select Company"
    ng-options="company for company in companies"
    ng-model="newUser.company" ng-required="true">
    </select>
    <span class="help-block" ng-show="addForm.addCompany.$invalid && !addForm.addCompany.$pristine">
    Your Company is required.
    </span>
    </div>
    </div>




    var newCompany = [{
    name: "Huawei", // -->COMPANY NAME
    email: "Drath@yahoo.com",
    phone: "123-123-1234",
    owner: "Drath",
    type: "buyer"
    },
    {
    name: "Asus", // -->COMPANY NAME
    email: "Vadar@yahoo.com",
    phone: "999-123-8888",
    owner: "Vadar",
    type: "supplier"
    },
    {
    name: "Acer", // -->COMPANY NAME
    email: "Radal@yahoo.com",
    phone: "676-989-8888",
    owner: "Randall",
    type: "supplier"
    }
    ];
    window.localStorage.setItem("newCompany", JSON.stringify(newCompany));











    share|improve this question



























      0












      0








      0








      I am trying to split an array into 2 types based on type: Buyer or Supplier. If you look at the last snippet, there is an array called newCompanies where there are company names with the type of company.



      I am trying to get that company array data from local storage and I want to split them into 2 arrays so that I can have 2 types of listboxes. One is the Buyer listbpx and the other is supplier listbox.



      Thanks in advance



      var companies = JSON.parse(localStorage.getItem("newCompany"));

      var splitted = companies.reduce(function(obj, item) {
      if (obj[item.type] == null) {
      obj[item.type] = ;
      }
      obj[item.type].push(item);
      return obj;
      }, {});

      splitted.buyer;
      splitted.supplier;
      $scope.companies.push(splitted.supplier);

      $scope.companies.push(splitted.buyer);


      <div class="form-group">
      <label class="control-label col-sm-2">Company</label>
      <div class="col-sm-10" ng-class="{ 'has-error' : addForm.addCompany.$invalid && !addForm.addCompany.$pristine }">
      <select class="form-control" name="addCompany"
      placeholder="Select Company"
      ng-options="company for company in companies"
      ng-model="newUser.company" ng-required="true">
      </select>
      <span class="help-block" ng-show="addForm.addCompany.$invalid && !addForm.addCompany.$pristine">
      Your Company is required.
      </span>
      </div>
      </div>




      var newCompany = [{
      name: "Huawei", // -->COMPANY NAME
      email: "Drath@yahoo.com",
      phone: "123-123-1234",
      owner: "Drath",
      type: "buyer"
      },
      {
      name: "Asus", // -->COMPANY NAME
      email: "Vadar@yahoo.com",
      phone: "999-123-8888",
      owner: "Vadar",
      type: "supplier"
      },
      {
      name: "Acer", // -->COMPANY NAME
      email: "Radal@yahoo.com",
      phone: "676-989-8888",
      owner: "Randall",
      type: "supplier"
      }
      ];
      window.localStorage.setItem("newCompany", JSON.stringify(newCompany));











      share|improve this question
















      I am trying to split an array into 2 types based on type: Buyer or Supplier. If you look at the last snippet, there is an array called newCompanies where there are company names with the type of company.



      I am trying to get that company array data from local storage and I want to split them into 2 arrays so that I can have 2 types of listboxes. One is the Buyer listbpx and the other is supplier listbox.



      Thanks in advance



      var companies = JSON.parse(localStorage.getItem("newCompany"));

      var splitted = companies.reduce(function(obj, item) {
      if (obj[item.type] == null) {
      obj[item.type] = ;
      }
      obj[item.type].push(item);
      return obj;
      }, {});

      splitted.buyer;
      splitted.supplier;
      $scope.companies.push(splitted.supplier);

      $scope.companies.push(splitted.buyer);


      <div class="form-group">
      <label class="control-label col-sm-2">Company</label>
      <div class="col-sm-10" ng-class="{ 'has-error' : addForm.addCompany.$invalid && !addForm.addCompany.$pristine }">
      <select class="form-control" name="addCompany"
      placeholder="Select Company"
      ng-options="company for company in companies"
      ng-model="newUser.company" ng-required="true">
      </select>
      <span class="help-block" ng-show="addForm.addCompany.$invalid && !addForm.addCompany.$pristine">
      Your Company is required.
      </span>
      </div>
      </div>




      var newCompany = [{
      name: "Huawei", // -->COMPANY NAME
      email: "Drath@yahoo.com",
      phone: "123-123-1234",
      owner: "Drath",
      type: "buyer"
      },
      {
      name: "Asus", // -->COMPANY NAME
      email: "Vadar@yahoo.com",
      phone: "999-123-8888",
      owner: "Vadar",
      type: "supplier"
      },
      {
      name: "Acer", // -->COMPANY NAME
      email: "Radal@yahoo.com",
      phone: "676-989-8888",
      owner: "Randall",
      type: "supplier"
      }
      ];
      window.localStorage.setItem("newCompany", JSON.stringify(newCompany));








      javascript html angularjs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 23:15









      georgeawg

      33.4k105168




      33.4k105168










      asked Nov 21 '18 at 21:27









      Vaibhav27Vaibhav27

      54




      54
























          2 Answers
          2






          active

          oldest

          votes


















          1

















          var newCompany = [{
          name: "Huawei", // -->COMPANY NAME
          email: "Drath@yahoo.com",
          phone: "123-123-1234",
          owner: "Drath",
          type: "buyer"
          },
          {
          name: "Asus", // -->COMPANY NAME
          email: "Vadar@yahoo.com",
          phone: "999-123-8888",
          owner: "Vadar",
          type: "supplier"
          },
          {
          name: "Acer", // -->COMPANY NAME
          email: "Radal@yahoo.com",
          phone: "676-989-8888",
          owner: "Randall",
          type: "supplier"
          }
          ];

          let buyers = , suppliers = ;
          for (let company of newCompany) {
          if (company.type === "buyer")
          buyers.push(company);
          else
          suppliers.push(company);
          }

          console.log("Buyers:");
          console.log(buyers);
          console.log("Suppliers:");
          console.log(suppliers);








          share|improve this answer
























          • Thank you so much. It totally works! Can you please tell me how this" let company of newCompany" works?

            – Vaibhav27
            Nov 22 '18 at 17:10











          • It's a foreach loop for iterables (like arrays, maps, strings, etc.), you can learn more about it here

            – Becks
            Nov 23 '18 at 17:19





















          0














          With a reduce:



          var companies = JSON.parse(window.localStorage.getItem('newCompany'));

          var splitted = companies.reduce(function (obj, item) {
          if (obj[item.type] == null) { obj[item.type] = ; }
          obj[item.type].push(item);
          return obj;
          }, {});


          Will result in splitted looking like this:



          {
          buyer: [{name: "Huawei", ... }],
          supplier: [{name: "Asus", ... }, {name: "Acer", ... }]
          }


          And then grab the information from splitted:



          splitted.buyer;    // -> [{name: "Huawei", ... }]
          splitted.supplier; // -> [{name: "Asus", ... }, {name: "Acer", ... }]


          This has the additional benefit, that if you add a third "type" of company later, you won't have to change a single line of code.






          share|improve this answer


























          • I tried it. Its not working. I am getting [object, object] in the listbox. I have updated the code in my question please check that.

            – Vaibhav27
            Nov 21 '18 at 22:19











          • The fact that you see [object Object] in the <select> elements has nothing to do with the way the array is divided, but it has to do with how Angular constructs the final HTML from the array contents. I'm not much of an expert on Angular to be honest, but by looking at the code you provided I'd suggest looking into ng-options and ng-model

            – David
            Nov 21 '18 at 22:34











          • @Vaibhav27 According to the AngularJS docs, you have to change ng-options to something like this: company.name for company in companies to display the name part: docs.angularjs.org/api/ng/directive/ngOptions

            – David
            Nov 21 '18 at 22:40













          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%2f53420686%2fhow-do-i-split-and-array-into-two-parts-based-on-type-angular-js%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1

















          var newCompany = [{
          name: "Huawei", // -->COMPANY NAME
          email: "Drath@yahoo.com",
          phone: "123-123-1234",
          owner: "Drath",
          type: "buyer"
          },
          {
          name: "Asus", // -->COMPANY NAME
          email: "Vadar@yahoo.com",
          phone: "999-123-8888",
          owner: "Vadar",
          type: "supplier"
          },
          {
          name: "Acer", // -->COMPANY NAME
          email: "Radal@yahoo.com",
          phone: "676-989-8888",
          owner: "Randall",
          type: "supplier"
          }
          ];

          let buyers = , suppliers = ;
          for (let company of newCompany) {
          if (company.type === "buyer")
          buyers.push(company);
          else
          suppliers.push(company);
          }

          console.log("Buyers:");
          console.log(buyers);
          console.log("Suppliers:");
          console.log(suppliers);








          share|improve this answer
























          • Thank you so much. It totally works! Can you please tell me how this" let company of newCompany" works?

            – Vaibhav27
            Nov 22 '18 at 17:10











          • It's a foreach loop for iterables (like arrays, maps, strings, etc.), you can learn more about it here

            – Becks
            Nov 23 '18 at 17:19


















          1

















          var newCompany = [{
          name: "Huawei", // -->COMPANY NAME
          email: "Drath@yahoo.com",
          phone: "123-123-1234",
          owner: "Drath",
          type: "buyer"
          },
          {
          name: "Asus", // -->COMPANY NAME
          email: "Vadar@yahoo.com",
          phone: "999-123-8888",
          owner: "Vadar",
          type: "supplier"
          },
          {
          name: "Acer", // -->COMPANY NAME
          email: "Radal@yahoo.com",
          phone: "676-989-8888",
          owner: "Randall",
          type: "supplier"
          }
          ];

          let buyers = , suppliers = ;
          for (let company of newCompany) {
          if (company.type === "buyer")
          buyers.push(company);
          else
          suppliers.push(company);
          }

          console.log("Buyers:");
          console.log(buyers);
          console.log("Suppliers:");
          console.log(suppliers);








          share|improve this answer
























          • Thank you so much. It totally works! Can you please tell me how this" let company of newCompany" works?

            – Vaibhav27
            Nov 22 '18 at 17:10











          • It's a foreach loop for iterables (like arrays, maps, strings, etc.), you can learn more about it here

            – Becks
            Nov 23 '18 at 17:19
















          1












          1








          1










          var newCompany = [{
          name: "Huawei", // -->COMPANY NAME
          email: "Drath@yahoo.com",
          phone: "123-123-1234",
          owner: "Drath",
          type: "buyer"
          },
          {
          name: "Asus", // -->COMPANY NAME
          email: "Vadar@yahoo.com",
          phone: "999-123-8888",
          owner: "Vadar",
          type: "supplier"
          },
          {
          name: "Acer", // -->COMPANY NAME
          email: "Radal@yahoo.com",
          phone: "676-989-8888",
          owner: "Randall",
          type: "supplier"
          }
          ];

          let buyers = , suppliers = ;
          for (let company of newCompany) {
          if (company.type === "buyer")
          buyers.push(company);
          else
          suppliers.push(company);
          }

          console.log("Buyers:");
          console.log(buyers);
          console.log("Suppliers:");
          console.log(suppliers);








          share|improve this answer
















          var newCompany = [{
          name: "Huawei", // -->COMPANY NAME
          email: "Drath@yahoo.com",
          phone: "123-123-1234",
          owner: "Drath",
          type: "buyer"
          },
          {
          name: "Asus", // -->COMPANY NAME
          email: "Vadar@yahoo.com",
          phone: "999-123-8888",
          owner: "Vadar",
          type: "supplier"
          },
          {
          name: "Acer", // -->COMPANY NAME
          email: "Radal@yahoo.com",
          phone: "676-989-8888",
          owner: "Randall",
          type: "supplier"
          }
          ];

          let buyers = , suppliers = ;
          for (let company of newCompany) {
          if (company.type === "buyer")
          buyers.push(company);
          else
          suppliers.push(company);
          }

          console.log("Buyers:");
          console.log(buyers);
          console.log("Suppliers:");
          console.log(suppliers);








          var newCompany = [{
          name: "Huawei", // -->COMPANY NAME
          email: "Drath@yahoo.com",
          phone: "123-123-1234",
          owner: "Drath",
          type: "buyer"
          },
          {
          name: "Asus", // -->COMPANY NAME
          email: "Vadar@yahoo.com",
          phone: "999-123-8888",
          owner: "Vadar",
          type: "supplier"
          },
          {
          name: "Acer", // -->COMPANY NAME
          email: "Radal@yahoo.com",
          phone: "676-989-8888",
          owner: "Randall",
          type: "supplier"
          }
          ];

          let buyers = , suppliers = ;
          for (let company of newCompany) {
          if (company.type === "buyer")
          buyers.push(company);
          else
          suppliers.push(company);
          }

          console.log("Buyers:");
          console.log(buyers);
          console.log("Suppliers:");
          console.log(suppliers);





          var newCompany = [{
          name: "Huawei", // -->COMPANY NAME
          email: "Drath@yahoo.com",
          phone: "123-123-1234",
          owner: "Drath",
          type: "buyer"
          },
          {
          name: "Asus", // -->COMPANY NAME
          email: "Vadar@yahoo.com",
          phone: "999-123-8888",
          owner: "Vadar",
          type: "supplier"
          },
          {
          name: "Acer", // -->COMPANY NAME
          email: "Radal@yahoo.com",
          phone: "676-989-8888",
          owner: "Randall",
          type: "supplier"
          }
          ];

          let buyers = , suppliers = ;
          for (let company of newCompany) {
          if (company.type === "buyer")
          buyers.push(company);
          else
          suppliers.push(company);
          }

          console.log("Buyers:");
          console.log(buyers);
          console.log("Suppliers:");
          console.log(suppliers);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 21:45









          BecksBecks

          342210




          342210













          • Thank you so much. It totally works! Can you please tell me how this" let company of newCompany" works?

            – Vaibhav27
            Nov 22 '18 at 17:10











          • It's a foreach loop for iterables (like arrays, maps, strings, etc.), you can learn more about it here

            – Becks
            Nov 23 '18 at 17:19





















          • Thank you so much. It totally works! Can you please tell me how this" let company of newCompany" works?

            – Vaibhav27
            Nov 22 '18 at 17:10











          • It's a foreach loop for iterables (like arrays, maps, strings, etc.), you can learn more about it here

            – Becks
            Nov 23 '18 at 17:19



















          Thank you so much. It totally works! Can you please tell me how this" let company of newCompany" works?

          – Vaibhav27
          Nov 22 '18 at 17:10





          Thank you so much. It totally works! Can you please tell me how this" let company of newCompany" works?

          – Vaibhav27
          Nov 22 '18 at 17:10













          It's a foreach loop for iterables (like arrays, maps, strings, etc.), you can learn more about it here

          – Becks
          Nov 23 '18 at 17:19







          It's a foreach loop for iterables (like arrays, maps, strings, etc.), you can learn more about it here

          – Becks
          Nov 23 '18 at 17:19















          0














          With a reduce:



          var companies = JSON.parse(window.localStorage.getItem('newCompany'));

          var splitted = companies.reduce(function (obj, item) {
          if (obj[item.type] == null) { obj[item.type] = ; }
          obj[item.type].push(item);
          return obj;
          }, {});


          Will result in splitted looking like this:



          {
          buyer: [{name: "Huawei", ... }],
          supplier: [{name: "Asus", ... }, {name: "Acer", ... }]
          }


          And then grab the information from splitted:



          splitted.buyer;    // -> [{name: "Huawei", ... }]
          splitted.supplier; // -> [{name: "Asus", ... }, {name: "Acer", ... }]


          This has the additional benefit, that if you add a third "type" of company later, you won't have to change a single line of code.






          share|improve this answer


























          • I tried it. Its not working. I am getting [object, object] in the listbox. I have updated the code in my question please check that.

            – Vaibhav27
            Nov 21 '18 at 22:19











          • The fact that you see [object Object] in the <select> elements has nothing to do with the way the array is divided, but it has to do with how Angular constructs the final HTML from the array contents. I'm not much of an expert on Angular to be honest, but by looking at the code you provided I'd suggest looking into ng-options and ng-model

            – David
            Nov 21 '18 at 22:34











          • @Vaibhav27 According to the AngularJS docs, you have to change ng-options to something like this: company.name for company in companies to display the name part: docs.angularjs.org/api/ng/directive/ngOptions

            – David
            Nov 21 '18 at 22:40


















          0














          With a reduce:



          var companies = JSON.parse(window.localStorage.getItem('newCompany'));

          var splitted = companies.reduce(function (obj, item) {
          if (obj[item.type] == null) { obj[item.type] = ; }
          obj[item.type].push(item);
          return obj;
          }, {});


          Will result in splitted looking like this:



          {
          buyer: [{name: "Huawei", ... }],
          supplier: [{name: "Asus", ... }, {name: "Acer", ... }]
          }


          And then grab the information from splitted:



          splitted.buyer;    // -> [{name: "Huawei", ... }]
          splitted.supplier; // -> [{name: "Asus", ... }, {name: "Acer", ... }]


          This has the additional benefit, that if you add a third "type" of company later, you won't have to change a single line of code.






          share|improve this answer


























          • I tried it. Its not working. I am getting [object, object] in the listbox. I have updated the code in my question please check that.

            – Vaibhav27
            Nov 21 '18 at 22:19











          • The fact that you see [object Object] in the <select> elements has nothing to do with the way the array is divided, but it has to do with how Angular constructs the final HTML from the array contents. I'm not much of an expert on Angular to be honest, but by looking at the code you provided I'd suggest looking into ng-options and ng-model

            – David
            Nov 21 '18 at 22:34











          • @Vaibhav27 According to the AngularJS docs, you have to change ng-options to something like this: company.name for company in companies to display the name part: docs.angularjs.org/api/ng/directive/ngOptions

            – David
            Nov 21 '18 at 22:40
















          0












          0








          0







          With a reduce:



          var companies = JSON.parse(window.localStorage.getItem('newCompany'));

          var splitted = companies.reduce(function (obj, item) {
          if (obj[item.type] == null) { obj[item.type] = ; }
          obj[item.type].push(item);
          return obj;
          }, {});


          Will result in splitted looking like this:



          {
          buyer: [{name: "Huawei", ... }],
          supplier: [{name: "Asus", ... }, {name: "Acer", ... }]
          }


          And then grab the information from splitted:



          splitted.buyer;    // -> [{name: "Huawei", ... }]
          splitted.supplier; // -> [{name: "Asus", ... }, {name: "Acer", ... }]


          This has the additional benefit, that if you add a third "type" of company later, you won't have to change a single line of code.






          share|improve this answer















          With a reduce:



          var companies = JSON.parse(window.localStorage.getItem('newCompany'));

          var splitted = companies.reduce(function (obj, item) {
          if (obj[item.type] == null) { obj[item.type] = ; }
          obj[item.type].push(item);
          return obj;
          }, {});


          Will result in splitted looking like this:



          {
          buyer: [{name: "Huawei", ... }],
          supplier: [{name: "Asus", ... }, {name: "Acer", ... }]
          }


          And then grab the information from splitted:



          splitted.buyer;    // -> [{name: "Huawei", ... }]
          splitted.supplier; // -> [{name: "Asus", ... }, {name: "Acer", ... }]


          This has the additional benefit, that if you add a third "type" of company later, you won't have to change a single line of code.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 '18 at 22:27

























          answered Nov 21 '18 at 21:43









          DavidDavid

          1,133116




          1,133116













          • I tried it. Its not working. I am getting [object, object] in the listbox. I have updated the code in my question please check that.

            – Vaibhav27
            Nov 21 '18 at 22:19











          • The fact that you see [object Object] in the <select> elements has nothing to do with the way the array is divided, but it has to do with how Angular constructs the final HTML from the array contents. I'm not much of an expert on Angular to be honest, but by looking at the code you provided I'd suggest looking into ng-options and ng-model

            – David
            Nov 21 '18 at 22:34











          • @Vaibhav27 According to the AngularJS docs, you have to change ng-options to something like this: company.name for company in companies to display the name part: docs.angularjs.org/api/ng/directive/ngOptions

            – David
            Nov 21 '18 at 22:40





















          • I tried it. Its not working. I am getting [object, object] in the listbox. I have updated the code in my question please check that.

            – Vaibhav27
            Nov 21 '18 at 22:19











          • The fact that you see [object Object] in the <select> elements has nothing to do with the way the array is divided, but it has to do with how Angular constructs the final HTML from the array contents. I'm not much of an expert on Angular to be honest, but by looking at the code you provided I'd suggest looking into ng-options and ng-model

            – David
            Nov 21 '18 at 22:34











          • @Vaibhav27 According to the AngularJS docs, you have to change ng-options to something like this: company.name for company in companies to display the name part: docs.angularjs.org/api/ng/directive/ngOptions

            – David
            Nov 21 '18 at 22:40



















          I tried it. Its not working. I am getting [object, object] in the listbox. I have updated the code in my question please check that.

          – Vaibhav27
          Nov 21 '18 at 22:19





          I tried it. Its not working. I am getting [object, object] in the listbox. I have updated the code in my question please check that.

          – Vaibhav27
          Nov 21 '18 at 22:19













          The fact that you see [object Object] in the <select> elements has nothing to do with the way the array is divided, but it has to do with how Angular constructs the final HTML from the array contents. I'm not much of an expert on Angular to be honest, but by looking at the code you provided I'd suggest looking into ng-options and ng-model

          – David
          Nov 21 '18 at 22:34





          The fact that you see [object Object] in the <select> elements has nothing to do with the way the array is divided, but it has to do with how Angular constructs the final HTML from the array contents. I'm not much of an expert on Angular to be honest, but by looking at the code you provided I'd suggest looking into ng-options and ng-model

          – David
          Nov 21 '18 at 22:34













          @Vaibhav27 According to the AngularJS docs, you have to change ng-options to something like this: company.name for company in companies to display the name part: docs.angularjs.org/api/ng/directive/ngOptions

          – David
          Nov 21 '18 at 22:40







          @Vaibhav27 According to the AngularJS docs, you have to change ng-options to something like this: company.name for company in companies to display the name part: docs.angularjs.org/api/ng/directive/ngOptions

          – David
          Nov 21 '18 at 22:40




















          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%2f53420686%2fhow-do-i-split-and-array-into-two-parts-based-on-type-angular-js%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

          MongoDB - Not Authorized To Execute Command

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

          How to fix TextFormField cause rebuild widget in Flutter