Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
var txt=" ";
var basket= {
                item1:"rice",
                item2:"salt",
                item3:"banana",
                item4:"cake",
                item5:"apple",
                item6:"grape",
                item7:"meat",
                item8:"mango",
                dress:{
                    shirt:{
                            1:"t-Blue",
                            2:"t-black",
                            3:"t-green",
                            4:"t-red",
                            6:"t-yellow",
                            7:"t-Orange",
                          },
                          
                    pants:{
                        a:"p-Blue",
                        b:"p-black",
                        c:"p-green",
                        d:"p-red",
                        e:"p-yellow",
                        f:"t-Orange",
                          },
                          
                     silk:{
                        a:"p-Blue",
                        b:"p-black",
                        c:"p-green",
                        d:"p-red",
                        e:"p-yellow",
                        f:"t-Orange",
                          }
                       }
            }
            
 for (x in basket)
 {
 txt+= basket[x]+","+" ";
 }
document.getElementById("p3").innerHTML=  txt; 


What I have tried:

I tried to print valus from an array in javascript. but its not working. can anyone can please tell me what is the problem.
Posted
Updated 23-May-16 0:30am
v2

1 solution

Your code works partially. I added more codes to print all data.
Refer - [Fix] How to print array to HTML page in javascript - JSFiddle[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-May-16 9:21am    
Good enough, a 5.
—SA
Thanks a lot Sergey. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900