jquery - JavaScript Multiple Arrays in Object -
i'm trying display of items in list below. organized them such in order filter them out.
for example, want titles separate array items contain (so titles display headers , items regular text.
here code far:
var general = { "hardcover" : { ["book a",4], ["book b",6], ["book c",5] } // ... other options }; (var title in general) { var title = ...; // assign title variable $('body').append("<h2>" + title + "</h2>"); for(var items in title) { // assign item variables separately var itemtitle = ...; var itemprice = ...; $('body').append(itemtitle + ": $" + itemprice); } }
so final output like:
hardcover
book a: $4
book b: $6
book c: $5
i made quick fiddle below full list: http://jsfiddle.net/gekp6q8y/1/
http://jsfiddle.net/gekp6q8y/3/
$( document ).ready(function() { var general = { "hardcover": [ ["book a", 4], ["book b", 6], ["book c", 5] ], "ebooks": [ ["ebook a", 14], ["ebook b", 98] ], "pdfs": [ ["pdf a", 2], ["pdf b", 1], ["pdf c", .5] ], "free texts": [ ["fa a", 4], ["fa b", 6], ["fa c", 5] ], }; (var title in general) { $(".contself").append("<h1 > " + title + "</h1>"); (var bookarr in general[title]) { // console.log(general[title][book]); var book = general[title][bookarr]; $(".contself").append("<li class='book' > " + book[0] + ' :$' + book[1] + "</li>"); } } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class='contself'></div>
Comments
Post a Comment