[ {name:'hi',data:'1,2,3,4,5'} , {name:'hello',data:'5,4,3,2,1'} ]
What I need is to apply a split on data
of each object in array so that the result would be:
[ {name:'hi',data:[1,2,3,4,5]} , {name:'hello',data:[5,4,3,2,1]} ]
I know I can loop through the array using for each
and produce a new array, but is there a better, faster method?
var arr = [{
name: 'hi',
data: '1,2,3,4,5'
}, {
name: 'hello',
data: '5,4,3,2,1'
}];
var new_arr = [];
for (i in arr) {
var temp = {};
temp.name = arr[i].name;
temp.data = arr[i].data.split(',');
new_arr.push(temp);
}