Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何仅通过点符号在 Javascript 对象中创建嵌套元素?像
a= {}; a.b = 100; //is valid a.x.y = 200; //is invalid?
第三个无效,因为a.x未定义。
a.x
并且您正在尝试将值设置为undefined property
undefined property
a= {}; a.b = 100; //is valid a.x = {}; a.x.y = 200; // This works
你不能完全。
a.x = {y: 200};