I have this file , " File.txt " formatted as a big array[ ] , in each index of this array placed in the .txt file there is a json i want to use later. I need to read the file , save each json and push it in an array using javascript. Every { content } , { content 2} represents a json .
File.txt
[
{
"nodes": [
{"id": "Source","label":"name","group": 0},
{"id": "Parent_1","label":"name","group": 1},
{"id": "Parent_2","label":"name","group": 1},
{"id": "Parent_3","label":"name","group": 1},
{"id": "Child_1","label":"name","group": 2},
{"id": "Child_2","label":"name","group": 2},
{"id": "Child_3","label":"name","group": 2},
{"id": "Child_4","label":"name", "group": 3}
],
"links": [
{ "source": "Source","target": "Parent_1"},
{ "source": "Source","target": "Parent_2"},
{ "source": "Source","target": "Parent_3"},
{ "source": "Source","target": "Child_1"},
{ "source": "Source","target": "Child_2"},
{ "source": "Source","target": "Child_3"},
{ "source": "Child_2","target": "Child_4"}
]
} ,
{
"nodes": [
{"id": "Source","label":"name","group": 0},
{"id": "Parent_1","label":"name","group": 1},
{"id": "Parent_2","label":"name","group": 1},
{"id": "Parent_3","label":"name","group": 1},
{"id": "Child_1","label":"name","group": 2},
{"id": "Child_2","label":"name","group": 2},
{"id": "Child_3","label":"name","group": 2},
{"id": "Child_4","label":"name", "group": 3}
],
"links": [
{ "source": "Source","target": "Parent_1"},
{ "source": "Source","target": "Parent_2"},
{ "source": "Source","target": "Parent_3"},
{ "source": "Source","target": "Child_1"},
{ "source": "Source","target": "Child_2"},
{ "source": "Source","target": "Child_3"},
{ "source": "Child_2","target": "Child_4"}
]
}
]
I have in mind something like this :
//The array i want to save all the data in
NewArray=[];
//Get the file name
var File = document.getElementById('File.txt');
//Make a loop so i can read each index of the file and save the content in the new array
for (i = 0; i < array.length; i++) {
NewArray[i] = "File.[i] ;
}

var data =, and then load it via a<script src="file.txt"></script>element.