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>
    )
  })
}
5
  • Object.entries(Data).map(([key,value]) => or else {Data[key]}. Commented Aug 21, 2020 at 7: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? Commented Aug 21, 2020 at 7: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. Commented Aug 21, 2020 at 8:08
  • ok got it thanks you Commented Aug 21, 2020 at 8:34
  • Check the documentation for Object.entries developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Aug 21, 2020 at 9:07

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.