I am using the map (several map getting the necessary elements inside the nested json) function. I am trying to get an output from the Neo4j database according to desired template. During the last map I am building part of desired output having this stored inside variable:
px.segments.map(function(pathSegment){
individual_path.push({
"start": pathSegment.start.properties.name,
"weight": pathSegment.relationship.properties.Weight.low,
"end": pathSegment.end.properties.name});
})
Then I try:
console.log(individual_path);
I am getting the following response (as one of the records has null value in the DB):
[ { start: 'A', weight: 0.6180339887498948, end: 'P2' } ]
[]
[ { start: 'P1', weight: 0.6180339887498948, end: 'A' },
{ start: 'A', weight: 0.6180339887498948, end: 'P2' } ]
[ { start: 'P1', weight: 0.6180339887498948, end: 'A' } ]
My question, how can I replace an empty array (while looping over the set of records) with non-empty, like this:
[ { start: 'A', weight: 0.0, end: 'A' } ]
to have at the end something like:
[ { start: 'A', weight: 0.6180339887498948, end: 'P2' } ]
*[ { start: 'A', weight: 0.0, end: 'A' } ]*
[ { start: 'P1', weight: 0.6180339887498948, end: 'A' },
{ start: 'A', weight: 0.6180339887498948, end: 'P2' } ]
[ { start: 'P1', weight: 0.6180339887498948, end: 'A' } ]
I was not quite clear, I will add the console.log(px); output:
Path {
start:
Node {
identity: Integer { low: 1, high: 0 },
labels: [ 'concept' ],
properties: { name: 'A', type: 'string' } },
end:
Node {
identity: Integer { low: 2, high: 0 },
labels: [ 'concept' ],
properties: { name: 'P2', type: 'string' } },
segments:
[ PathSegment { start: [Object], relationship: [Object], end: [Object] } ],
length: 1 }
Path {
start:
Node {
identity: Integer { low: 1, high: 0 },
labels: [ 'concept' ],
properties: { name: 'A', type: 'string' } },
end:
Node {
identity: Integer { low: 1, high: 0 },
labels: [ 'concept' ],
properties: { name: 'A', type: 'string' } },
segments: [],
length: 0 }
Path {
start:
Node {
identity: Integer { low: 0, high: 0 },
labels: [ 'concept' ],
properties: { name: 'P1', type: 'string' } },
end:
Node {
identity: Integer { low: 2, high: 0 },
labels: [ 'concept' ],
properties: { name: 'P2', type: 'string' } },
segments:
[ PathSegment { start: [Object], relationship: [Object], end: [Object] },
PathSegment { start: [Object], relationship: [Object], end: [Object] } ],
length: 2 }
Path {
start:
Node {
identity: Integer { low: 0, high: 0 },
labels: [ 'concept' ],
properties: { name: 'P1', type: 'string' } },
end:
Node {
identity: Integer { low: 1, high: 0 },
labels: [ 'concept' ],
properties: { name: 'A', type: 'string' } },
segments:
[ PathSegment { start: [Object], relationship: [Object], end: [Object] } ],
length: 1 }
As you can see one of the blocks has an empty element segment, namely the second path block. What I need is to be able to replace an empty element, with object of the type (start: '', weight: , end:'')
And here is the console.log(px.segments);:
[ PathSegment {
start: Node { identity: [Object], labels: [Array], properties: [Object] },
relationship:
Relationship {
identity: [Object],
start: [Object],
end: [Object],
type: 'link',
properties: [Object] },
end: Node { identity: [Object], labels: [Array], properties: [Object] } } ]
[]
[ PathSegment {
start: Node { identity: [Object], labels: [Array], properties: [Object] },
relationship:
Relationship {
identity: [Object],
start: [Object],
end: [Object],
type: 'link',
properties: [Object] },
end: Node { identity: [Object], labels: [Array], properties: [Object] } },
PathSegment {
start: Node { identity: [Object], labels: [Array], properties: [Object] },
relationship:
Relationship {
identity: [Object],
start: [Object],
end: [Object],
type: 'link',
properties: [Object] },
end: Node { identity: [Object], labels: [Array], properties: [Object] } } ]
[ PathSegment {
start: Node { identity: [Object], labels: [Array], properties: [Object] },
relationship:
Relationship {
identity: [Object],
start: [Object],
end: [Object],
type: 'link',
properties: [Object] },
end: Node { identity: [Object], labels: [Array], properties: [Object] } } ]