Skip to content
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

46:小菜解析 #75

Closed
MrRENGE opened this issue Apr 1, 2019 · 3 comments
Closed

46:小菜解析 #75

MrRENGE opened this issue Apr 1, 2019 · 3 comments

Comments

@MrRENGE
Copy link

MrRENGE commented Apr 1, 2019

结果最后变为一个稀疏数组[,,1,2]。
因为在对象中加入splice属性方法,和length属性后。这个对象变成一个类数组。属性名称可转换为数字时,会映射成为索引下标。所以对象实际可这样描述:[,,3,4],然后继续执行length 属性复制,length 原来值为4,length:2 语句将数组截断成为长度为2的数组。此时数组为[,,]。接着push(1)、push (2)。数组追加两个值,[,,1,2]。小菜看法,有错望指正!!!

@yygmind
Copy link
Contributor

yygmind commented Apr 2, 2019

更多查看 #76

@Jesseszhang
Copy link

结果最后变为一个稀疏数组[,,1,2]。
因为在对象中加入splice属性方法,和length属性后。这个对象变成一个类数组。属性名称可转换为数字时,会映射成为索引下标。所以对象实际可这样描述:[,,3,4],然后继续执行length 属性复制,length 原来值为4,length:2 语句将数组截断成为长度为2的数组。此时数组为[,,]。接着push(1)、push (2)。数组追加两个值,[,,1,2]。小菜看法,有错望指正!!!

正解!
var foo = {
'1': 'Python',
'8': 'Scala',
length: 10
}
Array.from(foo)
 [undefined, "Python", undefined, undefined, undefined, undefined, undefined, undefined, "Scala", undefined]
var foo = {
'1': 'Python',
'8': 'Scala',
length: 2
}
Array.from(foo)
[undefined, "Python"]
是要看length的长度的

@TheHtmler
Copy link

请教下,splice是如何将对象转为类数组的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants