Posts

Showing posts with the label forloop

Foreach in javascript

If you wanna use foreach to loop through an array (list) in javascript, do as the following example: var myarray = ["genius", "super", "god"]; myarray. forEach (function(value, index){     console.log(index + ": " + value); }); the result will be: 0: genius 1: super 2: god Tested in Chrome 45.

How to show the correct object numbers (counter) when using django-pagination

I'm using this template tag to output the order numbers of an object list in a for loop: {% for myobj in myobjlist %} {{ forloop.counter }} ... {% endfor %} But if I use pagination, the number will always start from 1 in a new page. Here is the trick to show the correct number: add to the counter (use zero index instead, counter0) the object index: {{ forloop.counter0|add:myobjlist.start_index }} Neat!