Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2677] iOS: Array has an extra entry with index = 'contains'

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionInvalid
Resolution Date2012-12-10T17:40:48.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsios
ReporterWalid Saliba
AssigneeMauro Parra-Miranda
Created2012-12-10T14:47:24.000+0000
Updated2016-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]);

Comments

  1. Walid Saliba 2012-12-10

    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.
  2. Daniel Sefton 2012-12-10

    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.
  3. Mauro Parra-Miranda 2013-11-24

    Invalid issue.

JSON Source