亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

替換數組數組內的空數組

替換數組數組內的空數組

狐的傳說 2021-07-12 13:01:21
我正在使用地圖(幾個地圖在嵌套的 json 中獲取必要的元素)函數。我正在嘗試根據所需的模板從 Neo4j 數據庫中獲取輸出。在最后一張地圖中,我正在構建所需輸出的一部分,并將其存儲在變量中: 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);我收到以下響應(因為其中一條記錄在數據庫中具有空值):[ { 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' } ]我的問題是,如何用非空替換空數組(在循環記錄集時),如下所示:[ { 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' } ]我不是很清楚,我會添加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:如您所見,其中一個塊有一個空元素段,即第二個路徑塊。我需要的是能夠用類型的對象替換空元素(開始:'',重量:,結束:'')
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 266 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號