How to add new attributes to objects in angularjs
data is an array of objects obtained from the background. I want to add attributes to value
The code is as follows:
angular.forEach(data, function(value, key){
});
过去多啦不再A梦2017-05-15 16:58:32
Use Array.prototype.forEach() directly
var friends=[{name:'Jack',age:16},{name:'John',age:22}];
friends.forEach(function(value,index){
value.sex='male';
});
console.log(friends);
習慣沉默2017-05-15 16:58:32
angular.forEach(data, function(value, index){
value.name = "something you like to put here";
});
给我你的怀抱2017-05-15 16:58:32
You can introduce the lodash library and use the _.map method. I often use it in projects for various data operations, which is very convenient. I have to complain about the API provided by the backend staff and make it more friendly. Isn’t that good for everyone?