-3

I have this var

var allwords = {};

And i need push more options in this array like:

allwords.push = {"Ctrl-Space": "autocomplete"};
allwords.push = {"Ctrl-pause": "closewindow"};

And look like this:

allwords = {"Ctrl-Space": "autocomplete", "Ctrl-pause": "closewindow"};

How can't i do?

John Stamoutsos
  • 353
  • 1
  • 3
  • 17
  • That isn't an array, for a start. I suggest setting aside your current task and working through some basic JavaScript tutorials. – T.J. Crowder Aug 14 '15 at 17:59

1 Answers1

2

push is for Array objects. For traditional objects, assign the properties manually like

var allwords = {};

allwords["Ctrl-Space"] = "autocomplete";
allwords["Ctrl-pause"] = "closewindow";

console.log(allwords);
AmmarCSE
  • 30,079
  • 5
  • 45
  • 53