0

I want to print keys and values inside jsx of react native, I get keys but also I want value simultaneously for that particular key.

{
  Object.keys(Data).map((key, index) => {
    return (
      <View style= {{ flexDirection: 'row' }}>
        <View>
          <Text>{ key }</Text>
        </View>
      </View>
    )
  })
}
F.H.
  • 884
  • 1
  • 11
  • 26
Janhvi
  • 1
  • 1
  • `Object.entries(Data).map(([key,value]) =>` or else `{Data[key]}`. – trincot Aug 21 '20 at 07:29
  • I got from the second but i didn't understood that object.keys will contain only the array of keys so Data array will contain keys so how it gets the values? – Janhvi Aug 21 '20 at 07:35
  • What's in a name, right? `Object.keys` gives only keys, and `Object.values` gives only values, and `Object.entries` gives both in an array. But anyway, if you have the key, you can just do `Data[key]` to get the corresponding value too. – trincot Aug 21 '20 at 08:08
  • ok got it thanks you – Janhvi Aug 21 '20 at 08:34
  • Check the documentation for Object.entries https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries – harisu Aug 21 '20 at 09:07

0 Answers0