0

I want to do this in js/jquery:

var events = new Array();
var $event1 = [id, name, starttime, startposition];
var $event2 = [id2, name2, starttime2, startposition2];
var $event3 = [id3, name3, starttime3, startposition3];
events["fistcolumn"].push($event1, $event2, $event3);

this doesn't work... can you please tell me how to do it?

Dirty-flow
2,30011 gold badges30 silver badges49 bronze badges
asked Aug 20, 2012 at 9:56
1
  • You've posted no jQuery code, so not sure why you tagged this as jquery and not javascript. Commented Aug 20, 2012 at 10:04

5 Answers 5

1
var events = {}, //lets try that with an object?
 event1 = [id, name, starttime, startposition],
 event2 = [id2, name2, starttime2, startposition2],
 event3 = [id3, name3, starttime3, startposition3];
//lets join the arrays and stick them in the object
events["fistcolumn"] = event1.concat(event2).concat(event3); 
//now events.fistcolumn (kinky name) contains all the values from the arrays
if (events.fistcolumn[5] == name2) //true
answered Aug 20, 2012 at 10:02
Sign up to request clarification or add additional context in comments.

Comments

0

There are no associative arrays in javascript, you can use an object:

var events = {};
events["firstcolumn"] = event1;

Also, lose the $ in front of your vars, that is php syntax :)

Update:

For your events, you should probably also use objects:

var event2 = { id: id2, name: name2, starttime: starttime2, ... };

answered Aug 20, 2012 at 9:58

1 Comment

"no associative arrays in javascript"? Sort of, but var foo = []; foo['bar'] = "everything is fine"; alert(foo['bar']); does not give an error. bar actually becomes a property of the array but outwardly it amounts to the appearance of association, hence indexed and associative behaviour can be exhibited in one array simultaneously.
0

This may work. Because if you want to do like below,

 events["fistcolumn"] = events1;

events must be an Object.

events.push($event1);
events.push($event2);
events.push($event3);
answered Aug 20, 2012 at 10:00

Comments

0
var events = new Array(); 
var $event1 = ['id', 'name', 'starttime', 'startposition']; 
var $event2 = ['id2', 'name2', 'starttime2', 'startposition2']; 
var $event3 = ['id3', 'name3', 'starttime3', 'startposition3']; 
events["fistcolumn"] = $event1.concat($event2).concat($event3);

I changed those variables to string for testing purposes only, you could change it back.

answered Aug 20, 2012 at 10:04

Comments

0
var events = {}; // events object
var $event1 = [id, name, starttime, startposition];
var $event2 = [id2, name2, starttime2, startposition2];
var $event3 = [id3, name3, starttime3, startposition3];

then you can either do like this

events["fistcolumn"] = [$event1, $event2, $event3];

or like this

events["fistcolumn"] = [];
events["fistcolumn"].push($event1);
events["fistcolumn"].push($event2);
events["fistcolumn"].push($event3);
answered Aug 20, 2012 at 10:40

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.