I have an array [1,2,3,4,5] and when insert into database I except to receive result be like [1,2,3,4,5] in database. But only loop for give me an expected result, map() and forEach() always give me disorder array like [1,3,4,5,2] or [4,3,2,5,1] and so on. This is my code:
arrayChild.map(async item => {
await this.repository.save(item)
});
arrayChild.forEach(async item => {
await this.repository.save(item)
});
for (let i = 0; i < arrayChild.length; i++) {
await this.repository.save(arrayChild[i])
}
Please give me the reason. Thank for your attention