I'm trying to wrap my head around this and was hoping you could help.
My goal is to create an object of arrays where each key is set by a variable and the values of this key are a filtered result of another array.
Okay, that was complicated to write, here is an example:
<!-- Markup -->
<section id="container">
<article class="class-1">1</article>
<article class="class-2">2</article>
<article class="class-3">3</article>
<article class="class-4">4</article>
<article class="class-5">5</article>
<article class="class-6">6</article>
<article class="class-7">7</article>
<article class="class-8">8</article>
<article class="class-9">9</article>
</section>
// Desired outcome:
// plugin variables are
{ columns:3 }
var cols = {
1 : [ $('.class-1') , $('.class-4') , $('.class-7') ],
2 : [ $('.class-2') , $('.class-5') , $('.class-8') ],
3 : [ $('.class-3') , $('.class-6') , $('.class-9') ]
};
// my jQuery so far:
// note : columns == 3
var cols = $.map( $('article','#container') , function(item, i) {
return {[ i%columns+1 : item ]};
});
How can I achieve what I need here? What am I doing wrong?
Any help would be much appreciated.
Thanks for reading,
Jannis