The Accumulator Array(Indices) is initialized correctly to an ’empty array’ during creation in a Reduce loop but on pushing values to it , it becomes ‘Undefined’.
Why does this happen ?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test.html</title>
</head>
<body>
<script>
var data = {'Number' : [1,2,3,4,5]};
const startNumber = 2;
const endNumber = 5;
Numbers_filtered_indices = data['Number'].reduce((indices,e,i,arr)=> {
console.log(`loop ${i}`);
console.log('Accumulator Array');
console.log(indices);
console.log(`e = ${e}`);
console.log(`i = ${i}`);
console.log(`arr = ${arr}`);
if(startNumber <= e && e <= endNumber){indices.push(i);return indices}}
,[])
console.log('Numbers_filtered_indices')
console.log(Numbers_filtered_indices)
</script>
</body>
</html>