fix(docs/mapping-types): fix wrong demo code.

get index before push, so the access of this index won't beyond the boundery.
This commit is contained in:
KaiYu Feng 2020-05-01 00:14:45 +08:00 committed by GitHub
parent 602b29cba7
commit 15748e871e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -138,8 +138,8 @@ the ``sum`` function iterates over to sum all the values.
if (keyIndex > 0) if (keyIndex > 0)
return true; return true;
else { else {
self.keys.push();
keyIndex = self.keys.length; keyIndex = self.keys.length;
self.keys.push();
self.data[key].keyIndex = keyIndex + 1; self.data[key].keyIndex = keyIndex + 1;
self.keys[keyIndex].key = key; self.keys[keyIndex].key = key;
self.size++; self.size++;