How to add a unique identity to an indefinite array of objects

has an indefinite array

arr = [{a:"",b:"",c:""}] abc 

Click the add button to push an object in arr

arr = [{a:"",b:"",c:""},{a:"",b:"",c:""},{a:"",b:"",c:""}]

Click the delete button to delete the corresponding object

arr = [{a:"",b:"",c:""},{a:"",b:"",c:""}]


I want to add an id to each object when clicking add. This id is unique when the id is deleted. The id that has been added will not change at this time.
arr = [{br / p >]

Sep.01,2021

use a count variable

var i = 0
arr = []
arr.push({id:iPP})
arr.push({id:iPP})
arr.push({id:iPP})

use js to set a guid for each element of the array

function guid() {
  function s4() {
    return Math.floor((1 + Math.random()) * 0x10000)
      .toString(16)
      .substring(1);
  }
  return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}

I understand what the downstairs owner means. Do you want to give a unique id, every time you add it to avoid deletion? If you want id to be the only one, it is a timestamp, and the timestamp will not be repeated


my idea is to determine a fixed id to distinguish which

this.$refs['check_cn'+item.id].resetFields();

doesn't seem to work.


this requires you to design binding verification rules through id when you start to do it, and then when you delete a form, there will be no verification confusion

Menu