You must use datatype in the context where it will be evaluated.
Same.
var pages = []; $('li.page').each(function () { var datatype = $(this).attr('data-type'), info = $(this).attr('data-info'), record = {}; record[datatype] = info; pages_order.push(record); });
You need only one var , it can be followed by several assignments, separated by a symbol,.
No need to use new Array , just use an array literal []
source share