1

question guys, I have this type of object:

activities: Object
       activitiy: some activity
       date: some date
       level: some level

what I am trying to achieve here is to make it like this

activities: Array[1]
    [0]Object

then what i want to do is push to the array of activities

activities.push(newobject);

This is not the right logic:

activities = $.map(myObj, function(value, index) {
return [value];});

So what should I do to achieve what I want. Above will just put each value of the object as an array value instead of the whole object itself.

1 Answer 1

2

Try:

activities = [activities];

to transform activities into an array that initially contains the original object. Then you can push new items into activities since it's now an array.

Sign up to request clarification or add additional context in comments.

1 Comment

perfect. MUCH easier than I thought

Your Answer

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.