How do I turn this array with keys
> dd
[ 'DeviceName',
'counter1',
'counter2',
'counter3',
'counter4' ]
into this object array with objects
[
{ data: 'DeviceName' },
{ data: 'counter1' },
{ data: 'counter2' },
{ data: 'counter3' },
{ data: 'counter4' }
]
I have tried this function, but the problem is that the data key is the same in them all.
Is there a way around this?
newdd=function toObject(arr) {
var rv = {};
var a =[];
for (var i = 0; i < arr.length; ++i) {
rv["data"] = arr[i];
a.push(rv);
}
return a;
}
This gives me:
> newdd(dd)
[ { data: 'counter4' },
{ data: 'counter4' },
{ data: 'counter4' },
{ data: 'counter4' },
{ data: 'counter4' } ]