Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

为啥这个js对象不是按代码执行顺序输出

var ob2 = {}
ob2.a = 1
console.log(ob2) // {a: 1}
ob2.b = 1
console.log(ob2) // {a: 1, b: 1}
ob2[342344] = 1
console.log(ob2)// {342344: 1, a: 1, b: 1}

如代码所示,感觉应该是输出 {a: 1, b: 1,342344: 1},怎么让他按照这种形式输出呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

这个输出是有规则的 如果是数字则按数字从小到大输出 如果是字母则按定义时顺序输出 可以自己查查


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.6k users

...