I have a javascript variable with the following:
var qh = [{"i":1,"q":1},{"i":2,"q":2},{"i":167,"q":2192}]
I need to map this to another variable to make:
var qq = [{"i":1,"a":1},{"i":2,"a":2},{"i":167,"a":2192}]
Using the native map function you can do it like this:
var qq = qh.map(function(el) { return { i: el.i, a: el.q } });
If you need support for older browsers, check out the underscore version which will use the native version of the function if available and polyfill it if not.
If you need support for older browsers AND you don't want to include an additional library, you'll have to do the donkey work yourself in a loop:
var qq = [];
for (var i = 0, obj; i < qh.length; i ++) {
obj = qh[i];
qq.push({ 'i': obj.i, 'a': obj.q });
}
qq = qh;