I want to map the keys of a large array into another key while removing the original key using Underscore.js' map() function.
large_array = _.map(data, function(element) {
element.b = element.a;
delete element.a;
return element;
});
console.log(large_array) // Returns an array with length == 0
Why would large_array have a length of zero?
I feel like I'm using the delete statement incorrrectly but I'm not sure.
Edit:
I may be abstracting this code too much, since simple runs seem to be working just fine.
The original data array is response from the FB.api('/me/friends', function(response) {...}
More specifically, it is an array of objects such as {id: "12345", name: "Bubba Watson"}
As this is a response from Facebook, each object is guaranteed to have the 'id' attribute
The actual code is changing the the 'id' property to a 'facebook_id' property.
FB.api('/me/friends', function(response) {
console.log(response.data); // Returns 600+ Array of Bubba Watson like objects, each with an id.
large_array = _.map(response.data, function(element) {
element.facebook_id = element.id;
delete element.id;
return element;
});
console.log(large_array); // Mysteriously Returns: {length: 0, __proto__: Array[0]}
}