0

There is code that checks for the presence of two or more objects in an array. When I add an object from obj to the map array, it looks to see if this object exists, if not, it displays the message "There is no object, we will add" and then adds this object, but if there is "The object already exists". When there are two identical objects in the array, it still says that it is not there What could be the problem?

let obj = [
    {id:1,title:1, img:"https://www.zonkpro.ru/zonk/assets/dice/mini/1.png"},
    {id:1,title:1, img:"https://www.zonkpro.ru/zonk/assets/dice/mini/1.png"},
    // {id:2,title:2, img:"https://www.zonkpro.ru/zonk/assets/dice/mini/2.png"},
    // {id:3,title:3, img:"https://www.zonkpro.ru/zonk/assets/dice/mini/3.png"},
    // {id:4,title:4, img:"https://www.zonkpro.ru/zonk/assets/dice/mini/4.png"},
    // {id:5,title:5, img:"https://www.zonkpro.ru/zonk/assets/dice/mini/5.png"},
    // {id:6,title:6, img:"https://www.zonkpro.ru/zonk/assets/dice/mini/6.png"},
    // {id:6,title:6, img:"https://www.zonkpro.ru/zonk/assets/dice/mini/6.png"},
]

let map = new Map()
for(let i=0;i<obj.length;i++){
    if(map.has(obj[i])){
        console.log('Object already exists')
    }else{
        console.log('There is no object, we will add')
        map.set(obj[i])
    }
}

console.log(map)
Venom
  • 47
  • 5

0 Answers0