I'm trying to create a Array using json objects. But the last object is repeating in the array. I've mentioned that in the below code output. Can anyone help me finding the solution of this problem
This is the code
let list = [
{
'title':'alfa',
'item':'box',
'count':2
},
{
'title':'beta',
'item':'ball',
'count':4
}
]
let ev = {}
let ev_arr = []
for(let i in list){
ev.title = list[i].title
ev.item = list[i].item
ev_arr.push(ev)
}
console.log(ev_arr)
My output I got
[
{
'title':'beta',
'item':'ball'
},
{
'title':'beta',
'item':'ball'
}
]
Expected Output
[
{
'title':'beta',
'item':'ball'
},
{
'title':'alfa',
'item':'box'
}
]