简体   繁体   English

在JavaScript中将对象插入数组

[英]Insert object in array in javascript

var x = [{id: string}];

I am trying x.push({id: 'abc'}); 我正在尝试x.push({id: 'abc'});

Its not functioning. 它不起作用。 Is Syntax correct? 语法正确吗?

in Following line string creating error because, I don't know why are you using this? 在以下行string创建错误中,因为,我不知道您为什么使用此?

var x = [{id: string}];

try this 尝试这个

var x = [];
x.push({id: 'abc'});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM