[AC-2677] iOS: Array has an extra entry with index = 'contains'
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2012-12-10T17:40:48.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | ios |
Reporter | Walid Saliba |
Assignee | Mauro Parra-Miranda |
Created | 2012-12-10T14:47:24.000+0000 |
Updated | 2016-03-08T07:41:46.000+0000 |
Description
When an array is accessed using the for (var key in array_name), it returns an extra entry with key = 'contains' at the end of the array. This does not happen if the array is accessed but iterating a key to array_legth -1.
Sample code that demonstrates the issue:
fields2 = [4, 5, 6, 7, 8];
for (var key in fields2)
Ti.API.info('FORM FIELD KEY ' + key + 'TITLE::' + fields2[key]);
for (var k = 0; k < fields2.length; k++)
Ti.API.info('FORM FIELD KEY ' + fields2[k]);
fields3 = ['4', '5', '6', '7', '8'];
for (var key in fields3)
Ti.API.info('FORM FIELD KEY ' + key + 'TITLE::' + fields3[key]);
for (var k = 0; k < fields3.length; k++)
Ti.API.info('FORM FIELD KEY ' + fields3[k]);
Found the source of the error. I had included a .js with the following statement: Array.prototype.contains = function(obj) { var i = this.length; while (i--) { if (this[i] === obj) { return true; } } return false; } Works well on Android, but causes the error described above when the same application is ran on iOS.
If the JS you included is part of the Titanium SDK, then let me know and I'll re-open. I'd notify its author or something.
Invalid issue.