Skip to content

Instantly share code, notes, and snippets.

@bnse
Created October 7, 2022 19:09
Show Gist options
  • Select an option

  • Save bnse/d88e52d2f3c6f07583ad0106ba7182e4 to your computer and use it in GitHub Desktop.

Select an option

Save bnse/d88e52d2f3c6f07583ad0106ba7182e4 to your computer and use it in GitHub Desktop.
change array to array object
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