-1
[{"a": 1000}, {"b": 2000}, {"c": 3000}, {"d": 4000}, {"e": 6000}, {"f": 7000}]

Using this data I want to make a list in react-native application like

a   1000
b   2000
c   3000
d   4000
e   5000
f   6000

Thanks in advance

6
  • Ok, and what is the problem you are facing? What's stopping you from achieve the desired result? Commented Nov 17, 2020 at 13:21
  • I don't know how to render it !! Commented Nov 17, 2020 at 13:22
  • So, please, start by watching some tutorials and documentations about react-native and FlatList. Then when you try it yourself and did not achieve what you expect, comeback to StackOverflow with the issue. I say that because of the community rules of SO, read How to Ask and minimal reproducible example Commented Nov 17, 2020 at 13:23
  • Yes I know but see my data array first I don't have same key value pairs at all, that is desired in react-native flatlist Commented Nov 17, 2020 at 13:29
  • So why don't you show us what you've tried until now and then we can help you? As I said, if you read How to Ask and minimal reproducible example you'll understand that you should add your code Commented Nov 17, 2020 at 13:32

1 Answer 1

0

Try this way

import React from 'react';
import { SafeAreaView, View, FlatList, StyleSheet, Text, StatusBar } from 'react-native';

const DATA = [{"a": 1000}, {"b": 2000}, {"c": 3000}, {"d": 4000}, {"e": 6000}, {"f": 7000}];
 

const App = () => {

  const renderItem = ({ item }) => {
    const key = Object.keys(item);
    const value = Object.values(item);
    return (
    <View style={{flexDirection:"row"}}>
        <Text>{key[0]}</Text>
        <Text>{value[0]}</Text>
    </View>
    );
  }

  return (
      <FlatList
        data={DATA}
        renderItem={renderItem}
        keyExtractor={(item, index) => index.toString()}
      />
  );
} 
Sign up to request clarification or add additional context in comments.

1 Comment

@Bhupesh did it worked? check I have updated my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.