I am trying to add multiple objects- Company Names into listBox Companies. I used $scope.companies.push(newCompany[0].name); to add the company into the list. But only the first object's company gets added because I used newCompany[0].name.
Now, how do I add the second company name into the list without entering newCpmpany[1].name ? Say there are 50 companies, I cannot add all 50 by doing this. Is there a better way to add all the names in one go? like a loop or incrementing the element or something? Looking for some help. Thanks in advance.
var newCompany = [{
name: "Huawei", // -->COMPANY NAME
email: "[email protected]",
phone: "123-123-1234",
owner: "Drath",
street: "Gin Blvd",
city: "Austin",
country: "USA",
duns:"123112321",
type: "buyer"
},
{
name: "Asus", // -->COMPANY NAME
email: "[email protected]",
phone: "999-123-8888",
owner: "Vadar",
street: "Vince Blvd",
city: "Dallas",
country: "USA",
duns: "123100000",
type: "supplier"
}];
window.localStorage.setItem("newCompany", JSON.stringify(newCompany));
$scope.companies = [];
var newCompany = JSON.parse(localStorage.getItem("newCompany"));
$scope.companies.push(newCompany[0].name);