Created
October 7, 2022 19:09
-
-
Save bnse/d88e52d2f3c6f07583ad0106ba7182e4 to your computer and use it in GitHub Desktop.
change array to array object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import './App.css' | |
| import MapList from './MapList' | |
| const people = [ | |
| 'string 1', | |
| 'string 2', | |
| 'string 3', | |
| 'string 4', | |
| 'string 5', | |
| 'string 6', | |
| ] | |
| let peopleObj = [] | |
| // for (let index in people) { | |
| // let data = { key: index, data: people[index] } | |
| // peopleObj.push(data) | |
| // } | |
| function ArrayToArrayObject(array) { | |
| let ArrayObj = [] | |
| for (let index in array) { | |
| let data = { key: index, data: array[index] } | |
| ArrayObj.push(data) | |
| } | |
| return ArrayObj | |
| } | |
| peopleObj = ArrayToArrayObject(people) | |
| function App() { | |
| return ( | |
| <div className="App"> | |
| <header className="App-header"> | |
| <h1>Hello, World!</h1> | |
| <MapList people={peopleObj} /> | |
| </header> | |
| </div> | |
| ) | |
| } | |
| export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment