-1

I have an object in javascript for settings for dataTables.

var dataTableSettings = {
  "iDisplayLength": 25,
  "bLengthChange": false,
  "bSortClasses": false,
};

I then have an if statement to add another option to the object:

if (last_location) {
  dataTableSettings.push(
    "oSearch": {"sSearch": last_location}
  );
}

I know that doesn't work because push() doesn't work on objects, how do I add to the object options list?

1
  • dataTableSettings.oSearch = {"sSearch": last_location}? Commented Jul 1, 2015 at 11:40

3 Answers 3

2
dataTableSettings.oSearch = { "sSearch": lastLocation };

Or

dataTableSettings['oSearch'] = { "sSearch": lastLocation };
Sign up to request clarification or add additional context in comments.

Comments

1

You have to do it this way:

if (last_location) {
  dataTableSettings.oSearch = {"sSearch": last_location};
}

OR

if (last_location) {
      dataTableSettings["oSearch"] = {"sSearch": last_location};
}

Comments

0

just do this :

dataTableSettings.oSearch = {"sSearch": last_location}

or this (both are equivalent ):

dataTableSettings['oSearch'] = {"sSearch": last_location}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.