I have the following JSON file called 'testing_numbers.json':
[{ "number":1,
"number":2,
"number":3,
"number":4,
"number":4,
"number":5,
"number":6,
"number":7,
"number":9,
"number":10,
"number":11}]
All I want to do is push each value to a list through a for loop, then append the list. My React code is like so:
import React, { Component } from 'react';
let values = require('./test_numbers.json');
class App extends Component {
state = { }
render() {
const numbers = []
for (var x in values) {
numbers.push(values[x].number)
}
return ( numbers );
}
}
export default App;
All I get as an output is the last variable in the JSON (which is 11), and not anything before that. It seems like I have something fundamentally wrong.
I am aware that I could just map the JSON first and then render it, but for my application, it would be better if I extracted data one at a time.
If anyone could help that would be great