search

Home  >  Q&A  >  body text

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)

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

reply all(3)I'll reply

  • 过去多啦不再A梦

    过去多啦不再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);

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-15 16:58:32

    angular.forEach(data, function(value,  index){
        value.name = "something you like to put here";
    });

    reply
    0
  • 给我你的怀抱

    给我你的怀抱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?

    reply
    0
  • Cancelreply