I am working on a network graph code that is rendered as json array.
I need to change to code in order to give the array data received from another file.
The code that I have:
var json = [
{
"adjacencies":
[
{
"nodeTo": "A",
"nodeFrom": "B",
"data":
{
"$color": "#557EAA"
}
}
],
"data":
{
"$color": "#909291",
"$type": "circle",
"$dim": 20
},
"id": "B",
"name": "B"
},
{
"adjacencies":
[
{
"nodeTo": "C",
"nodeFrom": "D",
"data":
{
"$color": "#416D9C"
}
}
],
"data":
{
"$color": "#83548B",
"$type": "circle",
"$dim": 20
},
"id": "D",
"name": "D"
},
];
I need to create a for loop that goes from 1 to x, and in every iteration, i add a value in the json array. (A value is composed of “adjacencies”, “data”, “id”, “name”)
Note that the nodeTo, nodeFrom, id and name values are stored in another array, so in the loop i can set their values.
Thanks in advance:)
I have tried the .push as follows:
var json = [];
var adjacencies = [];
for (i = 0; i < count; i++) {
var adjacencies = [];
var source = impactsString[i].Source;
var target = impactsString[i].Target;
var number = impactsString[i].NumberOfImpacts;
adjacencies.push({ nodeTo: target, nodeFrom: source });
json.push({ adjacencies: adjacencies, id: source, name: source });
}
But still not working
Use
Array.push()as follows: