JavaScript Objects Arrays & Printing












0














I want to create & print a list of 20 businesses.



Server only allows for HTML & JavaScript and no jQuery plugins.



I need to use an Arrays to add 20 more Businesses w/ minimum coding. Would be nice to have a code for easily adding 20 more businesses.



Each array needs to print a separate bulleted list / Unordered List ( "ul")



<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Yellow Pages</h2>

<p id="businessID"></p>

<script>

// Business Object
Business = {
"businessName",
"businessType",
"businessNumber",
}

// Constructor function for Business Object
function business( businessName, businessType, businessNumber ) {
this.businessName = name,
this.businessType = type,
this.businessNumber = number,
}

// Create 3 Business Objects
var business1 = new business("businessName1", "businessType1", "businessNumber1");
var business2 = new business("businessName2", "businessType2", "businessNumber2");
var business3 = new business("businessName3", "businessType3", "businessNumber3");

// Arrays of Business Objects, (Hopefully)
var businessesArray = [

{"businessName1", "businessType1", "businessNumber1"},
{"businessName2", "businessType2", "businessNumber2"},
{"businessName3", "businessType3", "businessNumber3"},
];

// Create Bulleted List & Print
var text = "<ul>";
for(i=0; i< businesses.length; i++){
for(j=0; j< businesses[i].length; j++){
text += "<li>" + businesses[i][j] + "</li>";
}

text += "<BR>";
}
text += "</ul>";
document.getElementById("businessID").innerHTML = text;

</script>
</body>
</html>


Try code here https://www.w3schools.com/html/tryit.asp?filename=tryhtml_default



Sorry, I am a novice. Please help more in details :-)



Thank you in advance for all your help with my very first question! :-)










share|improve this question




















  • 2




    Just use another loop
    – Ariel Alvarado
    Nov 19 '18 at 21:23










  • You should store the business information in an object instead of in an array. Then loop through the initial array which contains the business objects. [{}, {}]
    – Rastalamm
    Nov 19 '18 at 21:27
















0














I want to create & print a list of 20 businesses.



Server only allows for HTML & JavaScript and no jQuery plugins.



I need to use an Arrays to add 20 more Businesses w/ minimum coding. Would be nice to have a code for easily adding 20 more businesses.



Each array needs to print a separate bulleted list / Unordered List ( "ul")



<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Yellow Pages</h2>

<p id="businessID"></p>

<script>

// Business Object
Business = {
"businessName",
"businessType",
"businessNumber",
}

// Constructor function for Business Object
function business( businessName, businessType, businessNumber ) {
this.businessName = name,
this.businessType = type,
this.businessNumber = number,
}

// Create 3 Business Objects
var business1 = new business("businessName1", "businessType1", "businessNumber1");
var business2 = new business("businessName2", "businessType2", "businessNumber2");
var business3 = new business("businessName3", "businessType3", "businessNumber3");

// Arrays of Business Objects, (Hopefully)
var businessesArray = [

{"businessName1", "businessType1", "businessNumber1"},
{"businessName2", "businessType2", "businessNumber2"},
{"businessName3", "businessType3", "businessNumber3"},
];

// Create Bulleted List & Print
var text = "<ul>";
for(i=0; i< businesses.length; i++){
for(j=0; j< businesses[i].length; j++){
text += "<li>" + businesses[i][j] + "</li>";
}

text += "<BR>";
}
text += "</ul>";
document.getElementById("businessID").innerHTML = text;

</script>
</body>
</html>


Try code here https://www.w3schools.com/html/tryit.asp?filename=tryhtml_default



Sorry, I am a novice. Please help more in details :-)



Thank you in advance for all your help with my very first question! :-)










share|improve this question




















  • 2




    Just use another loop
    – Ariel Alvarado
    Nov 19 '18 at 21:23










  • You should store the business information in an object instead of in an array. Then loop through the initial array which contains the business objects. [{}, {}]
    – Rastalamm
    Nov 19 '18 at 21:27














0












0








0







I want to create & print a list of 20 businesses.



Server only allows for HTML & JavaScript and no jQuery plugins.



I need to use an Arrays to add 20 more Businesses w/ minimum coding. Would be nice to have a code for easily adding 20 more businesses.



Each array needs to print a separate bulleted list / Unordered List ( "ul")



<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Yellow Pages</h2>

<p id="businessID"></p>

<script>

// Business Object
Business = {
"businessName",
"businessType",
"businessNumber",
}

// Constructor function for Business Object
function business( businessName, businessType, businessNumber ) {
this.businessName = name,
this.businessType = type,
this.businessNumber = number,
}

// Create 3 Business Objects
var business1 = new business("businessName1", "businessType1", "businessNumber1");
var business2 = new business("businessName2", "businessType2", "businessNumber2");
var business3 = new business("businessName3", "businessType3", "businessNumber3");

// Arrays of Business Objects, (Hopefully)
var businessesArray = [

{"businessName1", "businessType1", "businessNumber1"},
{"businessName2", "businessType2", "businessNumber2"},
{"businessName3", "businessType3", "businessNumber3"},
];

// Create Bulleted List & Print
var text = "<ul>";
for(i=0; i< businesses.length; i++){
for(j=0; j< businesses[i].length; j++){
text += "<li>" + businesses[i][j] + "</li>";
}

text += "<BR>";
}
text += "</ul>";
document.getElementById("businessID").innerHTML = text;

</script>
</body>
</html>


Try code here https://www.w3schools.com/html/tryit.asp?filename=tryhtml_default



Sorry, I am a novice. Please help more in details :-)



Thank you in advance for all your help with my very first question! :-)










share|improve this question















I want to create & print a list of 20 businesses.



Server only allows for HTML & JavaScript and no jQuery plugins.



I need to use an Arrays to add 20 more Businesses w/ minimum coding. Would be nice to have a code for easily adding 20 more businesses.



Each array needs to print a separate bulleted list / Unordered List ( "ul")



<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Yellow Pages</h2>

<p id="businessID"></p>

<script>

// Business Object
Business = {
"businessName",
"businessType",
"businessNumber",
}

// Constructor function for Business Object
function business( businessName, businessType, businessNumber ) {
this.businessName = name,
this.businessType = type,
this.businessNumber = number,
}

// Create 3 Business Objects
var business1 = new business("businessName1", "businessType1", "businessNumber1");
var business2 = new business("businessName2", "businessType2", "businessNumber2");
var business3 = new business("businessName3", "businessType3", "businessNumber3");

// Arrays of Business Objects, (Hopefully)
var businessesArray = [

{"businessName1", "businessType1", "businessNumber1"},
{"businessName2", "businessType2", "businessNumber2"},
{"businessName3", "businessType3", "businessNumber3"},
];

// Create Bulleted List & Print
var text = "<ul>";
for(i=0; i< businesses.length; i++){
for(j=0; j< businesses[i].length; j++){
text += "<li>" + businesses[i][j] + "</li>";
}

text += "<BR>";
}
text += "</ul>";
document.getElementById("businessID").innerHTML = text;

</script>
</body>
</html>


Try code here https://www.w3schools.com/html/tryit.asp?filename=tryhtml_default



Sorry, I am a novice. Please help more in details :-)



Thank you in advance for all your help with my very first question! :-)







javascript arrays printing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 19:25









marc_s

572k12811061253




572k12811061253










asked Nov 19 '18 at 21:22









FarhangFarhang

83




83








  • 2




    Just use another loop
    – Ariel Alvarado
    Nov 19 '18 at 21:23










  • You should store the business information in an object instead of in an array. Then loop through the initial array which contains the business objects. [{}, {}]
    – Rastalamm
    Nov 19 '18 at 21:27














  • 2




    Just use another loop
    – Ariel Alvarado
    Nov 19 '18 at 21:23










  • You should store the business information in an object instead of in an array. Then loop through the initial array which contains the business objects. [{}, {}]
    – Rastalamm
    Nov 19 '18 at 21:27








2




2




Just use another loop
– Ariel Alvarado
Nov 19 '18 at 21:23




Just use another loop
– Ariel Alvarado
Nov 19 '18 at 21:23












You should store the business information in an object instead of in an array. Then loop through the initial array which contains the business objects. [{}, {}]
– Rastalamm
Nov 19 '18 at 21:27




You should store the business information in an object instead of in an array. Then loop through the initial array which contains the business objects. [{}, {}]
– Rastalamm
Nov 19 '18 at 21:27












1 Answer
1






active

oldest

votes


















1














To print the array based on the structure you've given, use two loops (one for the inner array and the other for the outer array):



for (var i = 0; i < businesses.length; i++) {
var ul = $("<ul/>");
$('#list').append(ul);
console.log((businesses[i]));
for (var j = 0; j < businesses[i].length; j++) {
var li = $("<li/>");
li.text(businesses[i][j]);
ul.append(li);
}
}


Here is a Fiddle demo: https://jsfiddle.net/zephyr_hex/vqodf1xn/13/






share|improve this answer





















  • Sorry, the server only allows me to use HTML & JavaScript code I can not use jQuery Thank you for your reply, thought!
    – Farhang
    Nov 20 '18 at 3:36










  • @Farhang : you should be able to use the same structure with JS. Two loops, like I've shown above.
    – devlin carnate
    Nov 20 '18 at 17:06










  • Thank you. What is "#list"? Is it a variable? Do I have to declare it before? How about "$"? Thanks!
    – Farhang
    Nov 21 '18 at 1:11










  • @Farhang : #list is the id of an HTML element, such as a div that the ul is appended to.
    – devlin carnate
    Nov 21 '18 at 18:20











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%2f53382818%2fjavascript-objects-arrays-printing%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














To print the array based on the structure you've given, use two loops (one for the inner array and the other for the outer array):



for (var i = 0; i < businesses.length; i++) {
var ul = $("<ul/>");
$('#list').append(ul);
console.log((businesses[i]));
for (var j = 0; j < businesses[i].length; j++) {
var li = $("<li/>");
li.text(businesses[i][j]);
ul.append(li);
}
}


Here is a Fiddle demo: https://jsfiddle.net/zephyr_hex/vqodf1xn/13/






share|improve this answer





















  • Sorry, the server only allows me to use HTML & JavaScript code I can not use jQuery Thank you for your reply, thought!
    – Farhang
    Nov 20 '18 at 3:36










  • @Farhang : you should be able to use the same structure with JS. Two loops, like I've shown above.
    – devlin carnate
    Nov 20 '18 at 17:06










  • Thank you. What is "#list"? Is it a variable? Do I have to declare it before? How about "$"? Thanks!
    – Farhang
    Nov 21 '18 at 1:11










  • @Farhang : #list is the id of an HTML element, such as a div that the ul is appended to.
    – devlin carnate
    Nov 21 '18 at 18:20
















1














To print the array based on the structure you've given, use two loops (one for the inner array and the other for the outer array):



for (var i = 0; i < businesses.length; i++) {
var ul = $("<ul/>");
$('#list').append(ul);
console.log((businesses[i]));
for (var j = 0; j < businesses[i].length; j++) {
var li = $("<li/>");
li.text(businesses[i][j]);
ul.append(li);
}
}


Here is a Fiddle demo: https://jsfiddle.net/zephyr_hex/vqodf1xn/13/






share|improve this answer





















  • Sorry, the server only allows me to use HTML & JavaScript code I can not use jQuery Thank you for your reply, thought!
    – Farhang
    Nov 20 '18 at 3:36










  • @Farhang : you should be able to use the same structure with JS. Two loops, like I've shown above.
    – devlin carnate
    Nov 20 '18 at 17:06










  • Thank you. What is "#list"? Is it a variable? Do I have to declare it before? How about "$"? Thanks!
    – Farhang
    Nov 21 '18 at 1:11










  • @Farhang : #list is the id of an HTML element, such as a div that the ul is appended to.
    – devlin carnate
    Nov 21 '18 at 18:20














1












1








1






To print the array based on the structure you've given, use two loops (one for the inner array and the other for the outer array):



for (var i = 0; i < businesses.length; i++) {
var ul = $("<ul/>");
$('#list').append(ul);
console.log((businesses[i]));
for (var j = 0; j < businesses[i].length; j++) {
var li = $("<li/>");
li.text(businesses[i][j]);
ul.append(li);
}
}


Here is a Fiddle demo: https://jsfiddle.net/zephyr_hex/vqodf1xn/13/






share|improve this answer












To print the array based on the structure you've given, use two loops (one for the inner array and the other for the outer array):



for (var i = 0; i < businesses.length; i++) {
var ul = $("<ul/>");
$('#list').append(ul);
console.log((businesses[i]));
for (var j = 0; j < businesses[i].length; j++) {
var li = $("<li/>");
li.text(businesses[i][j]);
ul.append(li);
}
}


Here is a Fiddle demo: https://jsfiddle.net/zephyr_hex/vqodf1xn/13/







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 21:43









devlin carnatedevlin carnate

5,12763358




5,12763358












  • Sorry, the server only allows me to use HTML & JavaScript code I can not use jQuery Thank you for your reply, thought!
    – Farhang
    Nov 20 '18 at 3:36










  • @Farhang : you should be able to use the same structure with JS. Two loops, like I've shown above.
    – devlin carnate
    Nov 20 '18 at 17:06










  • Thank you. What is "#list"? Is it a variable? Do I have to declare it before? How about "$"? Thanks!
    – Farhang
    Nov 21 '18 at 1:11










  • @Farhang : #list is the id of an HTML element, such as a div that the ul is appended to.
    – devlin carnate
    Nov 21 '18 at 18:20


















  • Sorry, the server only allows me to use HTML & JavaScript code I can not use jQuery Thank you for your reply, thought!
    – Farhang
    Nov 20 '18 at 3:36










  • @Farhang : you should be able to use the same structure with JS. Two loops, like I've shown above.
    – devlin carnate
    Nov 20 '18 at 17:06










  • Thank you. What is "#list"? Is it a variable? Do I have to declare it before? How about "$"? Thanks!
    – Farhang
    Nov 21 '18 at 1:11










  • @Farhang : #list is the id of an HTML element, such as a div that the ul is appended to.
    – devlin carnate
    Nov 21 '18 at 18:20
















Sorry, the server only allows me to use HTML & JavaScript code I can not use jQuery Thank you for your reply, thought!
– Farhang
Nov 20 '18 at 3:36




Sorry, the server only allows me to use HTML & JavaScript code I can not use jQuery Thank you for your reply, thought!
– Farhang
Nov 20 '18 at 3:36












@Farhang : you should be able to use the same structure with JS. Two loops, like I've shown above.
– devlin carnate
Nov 20 '18 at 17:06




@Farhang : you should be able to use the same structure with JS. Two loops, like I've shown above.
– devlin carnate
Nov 20 '18 at 17:06












Thank you. What is "#list"? Is it a variable? Do I have to declare it before? How about "$"? Thanks!
– Farhang
Nov 21 '18 at 1:11




Thank you. What is "#list"? Is it a variable? Do I have to declare it before? How about "$"? Thanks!
– Farhang
Nov 21 '18 at 1:11












@Farhang : #list is the id of an HTML element, such as a div that the ul is appended to.
– devlin carnate
Nov 21 '18 at 18:20




@Farhang : #list is the id of an HTML element, such as a div that the ul is appended to.
– devlin carnate
Nov 21 '18 at 18:20


















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%2f53382818%2fjavascript-objects-arrays-printing%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

Npm cannot find a required file even through it is in the searched directory

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