Answer the question
In order to leave comments, you need to log in
How to dynamically add value for id?
Hello! I have input. The data from which is written to an array of objects:
function() {
this.listValue.push({'title': this.value})
}
Answer the question
In order to leave comments, you need to log in
function() {
this.listValue.push({
'title': this.value,
'id': `Habr-id-${this.listValue.length}`
})
}
Download the library:
https://www.npmjs.com/package/uniqid
If you want a native solution, you can use timestamp as a relatively unique value.
But it will not work if more than 1 object is generated in 1 ms.
ps Well, in general, it is ideal that the id be generated by the backend when creating an entity, if such a creation occurs
new Date().getTime();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question