Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does IE 8 not support push?

I am trying to insert an key/value pair into a serializeArray(from jquery).

So I have something like

var form = $('#form');
var sendFormData = form.serializeArray();
sendFormData.push({ "name": "Name", "value": "test"});

In firefox this works yet in IE 8 I get

Line: 51 Error: Object doesn't support this property or method

So it seems to be pointing to this line. So does ie 8 not support push if so what is a way I can add a key/value pair that will work in all browsers(the 5 mains ones firefox, ie8, chrome, opera, safari)

like image 704
chobo2 Avatar asked Jul 18 '10 20:07

chobo2


2 Answers

What you have works (even in IE8), you can test it here: http://jsfiddle.net/ZAxzQ/

There must be something outside the question that you're doing to get that error :)

.push() has been around as long as the Array object, I've never seen a browser that doesn't support it...your unsupported error has to be coming from something else.

like image 62
Nick Craver Avatar answered Sep 21 '22 16:09

Nick Craver


This is not an exhaustive answer as it won't solve your problem, but the Array.push() method works in IE8:

var arr = [];
arr.push({ "name": "Test Name", "value": "Test Value"});
alert(arr[0].name);    // Displays "Test Name"

The above can also be re-written as follows:

var arr = [];
arr[arr.length] = { "name": "Test Name", "value": "Test Value"};
alert(arr[0].name);    // Displays "Test Name"
like image 39
Daniel Vassallo Avatar answered Sep 22 '22 16:09

Daniel Vassallo