How to check the change of an Array in JS

Asked

Viewed 44 times

0

I have an object array and want to perform a function when it changes its value (adding or removing the items). I’m using the md-checkbox of Angularjs with the checklist-model to include values within my array.

Example:

  var vetor = [
    {
      id: 1,
      nome: 'maça'
    },
    {
      id: 2,
      nome: 'laranja'
    },
    {
      id: 3,
      nome: 'banana'
    }
  ];

  alterouValor() {
    // minha função
  }

So from there, any value that adds or removes should also call the function alterouValor.

  • Hello Felipe. Your question reminded me that I had a question outline to ask here in the OS regarding the change of state of array. In this case, how is the change made? Direct or Angular? How is this done?

  • @Cmtecardeal Hello. I have a table with data-ng-repeat of objects (in the example I gave above would be the fruits I could add), so I have a checkbox to select all and one for each fruit. When I select some of the checkbox, automatically the object is already added in my list I set by checklist-model. I don’t know if it’s clearer.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.