I have a question about the output of the following code.
var _list = [{id:0}, {id:1}, {id:2}, {id:3}, {id:4}];
function storeList() {
for (var i = 0, j = _list.length; i < j; i++) {
var key = makeKey(_list[i].id);
_db.setValue(
function() {
console.log("OK: store a value of " + key);
},
function() {
throw "ERR: can't store a value of " + key;
},
databaseName,
key,
_list[i]);
}
}
storeList();
I expect it should output:
OK: store a value of 0
OK: store a value of 1
OK: store a value of 2
OK: store a value of 3
OK: store a value of 4
However, it outputs:
OK: store a value of 4
OK: store a value of 4
OK: store a value of 4
OK: store a value of 4
OK: store a value of 4
Why? and, what is the correct way to output? I run this javascript code on Android Webview.
Thanks in advance.