React-Native Map() data structure?

Viewed 2037

Does react-native not support javascript's Map()? The following code is returning an empty object:

  const x = new Map()
  x.set(1, 'a')
  x.set(2, 'b')
  console.log(x)
1 Answers

react-native only supports a subset of Javascript functionality as listed here. This may explain the reason for the unexpected behaviour.

To achieve this what you're requiring in your react-native app, you could use an object to map key/value pairs in a similar way like so:

const x = {}; 
x[1] = 'a'; 
x[2] = 'b';
console.log(x);
Related