I have a problem with splitting the array into to separate arrays Odd and Even. What I did was:
componentDidMount() {
axios.get( `${this.props.cmsUrl}types/genres`)
.then(response => { if ( response.data !== undefined ) {
let even = [];
let odd = [];
let allData = ["a", "b", "c", "d", "e", "f", "g", "h", ];
for (var i = 0; i < allData.length; ++i) {
if ( ( allData[i] % 2 ) === 0) {
even.push(allData[i]);
}
else {
odd.push(allData[i]);
}
};
console.log("allData : ",allData);
console.log("even : ",even);
console.log("even : ",odd);
}}
)
}
What I really was expecting is
allData = [a, b, c, d]
odd = [a , c]
even = [b, d]
But what really happened is
allData = even
odd = empty array
is this my problem => ( allData[i] % 2 ) === 1
The console.log is :
allData : (8) ["a", "b", "c", "d", "e", "f", "g", "h"]0: "a"1: "b"2: "c"3:
"d"4: "e"5: "f"6: "g"7: "h"length: 8__proto__: Array(0)
details.js:56 even : []length: 0__proto__: Array(0)
details.js:57 odd : (8) ["a", "b", "c", "d", "e", "f", "g", "h"]0:
"a"1: "b"2: "c"3: "d"4: "e"5: "f"6: "g"7: "h"length: 8__proto__: Array(0)
Thanks