我目前尝试使用该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)