简体   繁体   中英

Repeat an array object with key and values with map in react js

Hi i want to repeat an array object including object keys(once) and all the object values with map function

[
   { name: 'abc', age:'1' },
   { name: 'def', age:'2' },
   { name: 'ghi', age:'3' }
]

and i want repeat like this

name  age
abc    1
def    2
ghi    3

thanks

 let data = [
   { name: 'abc', age:'1' },
   { name: 'def', age:'2' },
   { name: 'ghi', age:'3' }
  ]

  rows = [] ; for (i in data[0]) {rows.push(i)}

Here you can display rows using "rows" array Below code is to display columns

   data.map(item => {rows.map(row => {console.log(item[row])})})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM