我正在使用地圖(幾個(gè)地圖在嵌套的 json 中獲取必要的元素)函數(shù)。我正在嘗試根據(jù)所需的模板從 Neo4j 數(shù)據(jù)庫中獲取輸出。在最后一張地圖中,我正在構(gòu)建所需輸出的一部分,并將其存儲(chǔ)在變量中: px.segments.map(function(pathSegment){ individual_path.push({ "start": pathSegment.start.properties.name, "weight": pathSegment.relationship.properties.Weight.low, "end": pathSegment.end.properties.name}); })然后我嘗試: console.log(individual_path);我收到以下響應(yīng)(因?yàn)槠渲幸粭l記錄在數(shù)據(jù)庫中具有空值):[ { 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' } ]我的問題是,如何用非空替換空數(shù)組(在循環(huán)記錄集時(shí)),如下所示:[ { start: 'A', weight: 0.0, end: 'A' } ]最后有類似的東西:[ { 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' } ]我不是很清楚,我會(huì)添加console.log(px); 輸出: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:如您所見,其中一個(gè)塊有一個(gè)空元素段,即第二個(gè)路徑塊。我需要的是能夠用類型的對(duì)象替換空元素(開始:'',重量:,結(jié)束:'')
替換數(shù)組數(shù)組內(nèi)的空數(shù)組
狐的傳說
2021-07-12 13:01:21