Realm-js: calling Object.Values() on a RealmList has different behavior on iOS device

Created on 23 Aug 2017  路  2Comments  路  Source: realm/realm-js

Goals

convert RealmList to Array

Expected Results

Object.values(realm.objects('MyObject')) should return an array of realmObjects

Actual Results

the returned array is empty, only when running on an iOS device but not on android or in simulator, or when using chrome debugging

Steps to Reproduce

  1. copy below code sample
  2. test on iOS device, not simulator, and not using remote debugging (code must be executed on iOS device)

Code Sample

    console.warn(Object.values(realm.objects('MyObject')).length)

Version of Realm and Tooling

  • Realm JS SDK Version: latest
  • Node or React Native: React Native
  • Client OS & Version: iOS 11
  • Which debugger for React Native: None
O-Community T-Bug

Most helpful comment

I think you should use Array.from(realm.objects('MyObject')) instead - Object.values() relies on the object having enumerable own properties.

That said, maybe we should check why Realm.Results has enumerable properties on Android, but not on iOS, given that they're both using JavaScriptCore.

All 2 comments

I think you should use Array.from(realm.objects('MyObject')) instead - Object.values() relies on the object having enumerable own properties.

That said, maybe we should check why Realm.Results has enumerable properties on Android, but not on iOS, given that they're both using JavaScriptCore.

Thanks @fealebenpae , using Array.from is a fine solution for me, just wanted to make sure the realm team was aware of this weird inconsistency.

Was this page helpful?
0 / 5 - 0 ratings