Javascript push() - 未定义的输出

Luk*_*yyy 0 javascript push undefined

我目前尝试使用该push()功能安全地保护阵列中不同用户的数据.
这是我目前的代码:

function data()
{

    var information = [];
    var imgs = '';
    var percentage;

    var imgs = 'ABC';
    var percentage = '1';

    information.push({ imgs: imgs, chance: percentage });

    var imgs = 'DEF';
    var percentage = '2';

    information.push({ imgs: imgs, chance: percentage });

    console.log(information);

    information.forEach(function(deposit)
    {
        var deposit=deposit.imgs;
        var chance=deposit.chance;

        console.log(deposit);
        console.log(chance);
    });


}
Run Code Online (Sandbox Code Playgroud)

这是输出console.log(information):

[ { imgs: 'ABC', chance: '1' }, { imgs: 'DEF', chance: '2' } ]
Run Code Online (Sandbox Code Playgroud)

这是输出information.forEach(function(deposit):

ABC
undefined
DEF
undefined
Run Code Online (Sandbox Code Playgroud)

那就是我的问题.正如你所看到的,它会输出机会,undefined但它应该输出1和2.任何人都知道它为什么这样做并知道如何解决它?

Uly*_* BN 6

在下一行,您重新分配您的存款对象:

var deposit=deposit.imgs;
Run Code Online (Sandbox Code Playgroud)

只需更改此变量名称即可.或在存款前分配机会.