JavaScript fill an array with getElementById fill array with random numbers,fill array with zeros,fill

In your code, return immediately terminates the function before any of the iterations have finished. Another problem is that .value only works for input-like elements - to extract the text from a div, access its textContent property.

How about using Array.from and its built in mapping function, which doesn't require any external mutation?

const graphData = Array.from(
  { length: 8 },
  (_, i) => Number(document.getElementById('E1_INV_Funds' + i).textContent)
);
console.log(graphData);
<div id="E1_INV_Funds0">1</div>
<div id="E1_INV_Funds1">2</div>
<div id="E1_INV_Funds2">3</div>
<div id="E1_INV_Funds3">4</div>
<div id="E1_INV_Funds4">5</div>
<div id="E1_INV_Funds5">6</div>
<div id="E1_INV_Funds6">7</div>
<div id="E1_INV_Funds7">8</div>
Answer:1

You never invoked function fillData(), also there few more corrections, replace value with innerHTML, here document.getElementById("E1_INV_Funds" + i).innerHTML

and move outside of loop return graphData;

var graphData = []; /* find all where id starts with `E1_INV_Funds` */
document.querySelectorAll('[id^=E1_INV_Funds]').forEach(function(el) {
  graphData.push(+(el.textContent || el.innerHTML) || 0); /* parse as number */
});
console.log(graphData);
<div id="E1_INV_Funds0">1</div>
<div id="E1_INV_Funds1">2</div>
<div id="E1_INV_Funds2">3</div>
<div id="E1_INV_Funds3">4</div>
<div id="E1_INV_Funds4">5</div>
<div id="E1_INV_Funds5">6</div>
<div id="E1_INV_Funds6">7</div>
<div id="E1_INV_Funds7">8</div>
Answer:2

I have two 'localStorage' items, summaryForm and projectForm. Currently I use two statements to remove them, localStorage.removeItem("summaryForm"); localStorage.removeItem("projectForm"); Is it ...

I have two 'localStorage' items, summaryForm and projectForm. Currently I use two statements to remove them, localStorage.removeItem("summaryForm"); localStorage.removeItem("projectForm"); Is it ...

  1. remove multiple items from localstorage

I'm trying to keep a grid's filter after updating a row. When I click on a row in the grid, I open a dialog where I update the informations for this row, and then I look for the clicked row in the ...

I'm trying to keep a grid's filter after updating a row. When I click on a row in the grid, I open a dialog where I update the informations for this row, and then I look for the clicked row in the ...

  1. keep rank after filter tableau
  2. keep rows hidden after filter
  3. primefaces datatable keep filter after update

Purpose: A user can choose a Product Type and variation of that Product Type. I need to track every Product Type added and how many variations were added. For Example, item 1: Shirt > Long Sleeve (1) ...

Purpose: A user can choose a Product Type and variation of that Product Type. I need to track every Product Type added and how many variations were added. For Example, item 1: Shirt > Long Sleeve (1) ...

I have read another question on stackoverflow, he said: A closure is one way of supporting first-class functions; it is an expression that can reference variables within its scope (when it was ...

I have read another question on stackoverflow, he said: A closure is one way of supporting first-class functions; it is an expression that can reference variables within its scope (when it was ...

  1. javascript closures definition