Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react JSON data to display in a table

<tbody>
{
  Object.keys(this.state.birth_details).map(function (element) {
    return (
      <tr key={element}>
        <td>{element}</td>
        <td>{this.state.birth_details[element]}</td>
      </tr>
    );
  })
}
</tbody>
Comment

display json data in html table react

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React, { useState, useEffect } from 'react';
import '../tabledata.css';
 
function TableData() {
    const [data, getData] = useState([])
    const URL = 'https://jsonplaceholder.typicode.com/posts';
 
    useEffect(() => {
        fetchData()
    }, [])
 
 
    const fetchData = () => {
        fetch(URL)
            .then((res) =>
                res.json())
 
            .then((response) => {
                console.log(response);
                getData(response);
            })
 
    }
 
    return (
        <>
            <h1>How to display JSON data to table in React JS</h1>
            <tbody>
                <tr>
                    <th>User Id</th>
                    <th>Id</th>
                    <th>Title</th>
                    <th>Description</th>
                </tr>
                {data.map((item, i) => (
                    <tr key={i}>
                        <td>{item.userId}</td>
                        <td>{item.id}</td>
                        <td>{item.title}</td>
                        <td>{item.body}</td>
                    </tr>
                ))}
            </tbody>
 
        </>
    );
}
 
export default TableData;
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript function length 
Javascript :: join array 
Javascript :: react using proptypes 
Javascript :: inverse of stringify js 
Javascript :: can we send raw json in get method in flutter 
Javascript :: set value lookup javascript dynamics 365 
Javascript :: js array get index 
Javascript :: react native meter 
Javascript :: js unique string array 
Javascript :: angular read config from json 
Javascript :: open new window javascript 
Javascript :: same click event in multiple elements in on event 
Javascript :: exec reges 
Javascript :: truncate string in javascript 
Javascript :: socket io query 
Javascript :: react bootstrap col not working 
Javascript :: javascript bitwise operators 
Javascript :: get data from url using react 
Javascript :: javascript find the second highest Element from array 
Javascript :: lodash update object by id in array 
Javascript :: javascript range between two numbers 
Javascript :: jquery sum table column td 
Javascript :: bson to json converter 
Javascript :: js get current year last 2 digits substring 
Javascript :: what is redux 
Javascript :: js remove key from object 
Javascript :: document fragment 
Javascript :: gitignore subfolders 
Javascript :: express reload page after post 
Javascript :: javascript includes check object 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =