i want to print index and its element side by side in JS and C++. like this:
arr = [1,2,3,4,5]
[ {0 : 1},
{1 : 2},
{2 : 3},
{3 : 4},
{4 : 5} ]
I have done like this, but not able to
const arr = [1,2,3,4,5]
for (let i = 0; i < arr.length; i++) {
let obj = {};
let emptArr = [];
obj.i = arr[i];
emptArr.push(obj);
console.log(emptArr);
}