data.agent_id = agentID;
As you mentioned, push
only works on an Array instance.
문제
I am trying to add more data to my data object before passed in ajax call. I know push won't work because it is not an array. What would the alternative to push be for an object?
var data = {
street: $('#FullStreetAddress').val(),
city: $('#City').val(),
state: $('#State').val(),
doc_name: []
};
data.push({
agent_id: agentID,
});
Thanks
해결책
data.agent_id = agentID;
As you mentioned, push
only works on an Array instance.
다른 팁
Although you can use the property style syntax:
data.agent_id = agentID;
Using brackets is slightly more robust:
data['agent_id'] = agentID;
This is because any string can be used as a key in an object, but not as a property name. Eg:
data['agent.id'] = agentID; // works
data.agent.id = agentID; // error