-
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
splice插入 #575
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
let a = ['A1', 'A2', 'B1', 'B2', 'C1', 'C2', 'D1', 'D2'];
let b = ['A', 'B', 'C', 'D'];
let i = 0;
let m = 0;
for (let index = 0; index < a.length; index++) {
if (index % 2 == 0 && b[i]) {
++m;
// 插入位置的为 奇数 插入数组元素对应的索引 + 1
// i 也可以换成 b.indexOf(b[i]) + 1
a.splice((2 * m - 1) + i + 1, 0, b[i]);
i++;
}
}
The text was updated successfully, but these errors were encountered: