var x = [{id: string}];
I am trying x.push({id: 'abc'});
Its not functioning. Is Syntax correct?
asked Nov 14, 2013 at 13:53
Sangram Singh
7,19115 gold badges52 silver badges79 bronze badges
1 Answer 1
in Following line string creating error because, I don't know why are you using this?
var x = [{id: string}];
try this
var x = [];
x.push({id: 'abc'});
answered Nov 14, 2013 at 13:54
Govind Malviya
13.8k17 gold badges70 silver badges95 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
x[x.length] = {id: 'abc'};stringwill throw a reference error (But I guess this was just for illustrational purposes?). What is the exact error message? You might want to quote your identifiers though, because you have to watch out for reserved words if you use them unquoted.x.push({'id' : 'abc'});var x = []