-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
先声明一个长度12,元素都是null 的数据,再循环obj 的key #565
Comments
let sele = { 1: 222, 2: 123, 5: 888 };
function tansformSele(obj) {
obj.length = 13;
let res = Array.from(obj).map((d) => {
if (!d) {
return null;
} else {
return d;
}
});
res.shift();
return res;
}
sele = tansformSele(sele);
console.log("结果:", sele); // (12) [222, 123, null, null, 888, null, null, null, null, null, null, null] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
let sele = { 1: 222, 2: 123, 5: 888 }
function tansformSele(obj) {
let res = [null, null, null, null, null, null, null, null, null, null, null, null]
for (const [key, value] of Object.entries(obj)) {
res[key - 1] = value
}
return res
}
sele = tansformSele(sele)
console.log("结果:", sele); // (12) [222, 123, null, null, 888, null, null, null, null, null, null, null]
The text was updated successfully, but these errors were encountered: