Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCraig Watson
27,930 PointsCreate an multi-dimensional array from objects in localStorage?
Hi all,
This is a bit beyond my JS know how, I have a shortlisting feature on a website that is seemingly working OK at the moment, however, I would like to list out the items under specific headings should they match a specific category.
It may help to have a peek at the site were this is all going on - Watson Memorials
I am using the following JS to loop the localStorage
Object.keys(localStorage).forEach(function(key){
var openLargeCol = '<div class="col-12 col-sm-12 col-md-6 col-lg-6 mb-5">';
var openCol = '<div class="col-12 col-sm-6 col-md-6 col-lg-4 mb-5">';
var closeCol = '</div>';
if ( key.match('^K_') ) {
$('#shortlist-container > .row').prepend( openLargeCol + localStorage.getItem(key) + closeCol );
} else {
$('#shortlist-container > .row').prepend( openCol + localStorage.getItem(key) + closeCol );
}
});
The key comes from the items id=""
attribute, they are prefixed with short letter codes for each type of memorial on show, this should help sort them.
As I say the end goal is to loop through localStorage
and spit out items under relevant headings rather than just in the order they were added.
Any help will be much appreciated!
Craig