angular.js - How to add new attributes to objects in angularjs (for example, I got an object o from the background, and I want to add a custom attribute name to o)
天蓬老师
天蓬老师 2017-05-15 16:56:32
0
3
835

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){
        
     });
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
过去多啦不再A梦

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);
習慣沉默
angular.forEach(data, function(value,  index){
    value.name = "something you like to put here";
});
给我你的怀抱

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?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template