【问题标题】:Is there a way that when I push data it doesn't show output the last line?有没有一种方法可以在我推送数据时不在最后一行显示输出?
【发布时间】:2023-01-19 23:06:45
【问题描述】:
let row = warehouse_delivery_transaction.find(x => x.kerry_status_name === 'CCC')
    if (!row) {
      let item = warehouse_delivery_transaction.find(x => x.kerry_status_name === 'BBB')
      if (item) {
        warehouse_delivery_transaction.push({
          code: item.code,
          kerry_status_name: 'CCC',
          location: '',
          status_date: item.status_date
        })
      }
    }

之前输出

1.AAA
2.BBB
3.DDD

推送数据后的输出

1.AAA
2.BBB
3.DDD
4.CCC

我希望它像这样出来。

1.AAA
2.BBB
3.CCC
4.DDD

【问题讨论】:

    标签: javascript node.js push


    【解决方案1】:

    使用Array.prototype.splice()插入到warehouse_delivery_transaction.length-1位置

    let warehouse_delivery_transaction = [{
        code: 'aa',
        kerry_status_name: 'AAA',
        location: '',
        status_date: 'aa'
      },
      {
        code: 'bb',
        kerry_status_name: 'BBB',
        location: '',
        status_date: 'bb'
      }, {
        code: 'dd',
        kerry_status_name: 'DDD',
        location: '',
        status_date: 'dd'
      }
    ]
    
    console.log('Before: ', warehouse_delivery_transaction)
    
    let row = warehouse_delivery_transaction.find(x => x.kerry_status_name === 'CCC')
    if (!row) {
      //let item = warehouse_delivery_transaction.find(x => x.kerry_status_name === 'BBB')    
      //if (item) {
      warehouse_delivery_transaction.splice(warehouse_delivery_transaction.length - 1, 0, {
        code: 'cc',
        kerry_status_name: 'CCC',
        location: '',
        status_date: 'cc'
      })
      //}
    }
    
    console.log('After: ', warehouse_delivery_transaction)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      相关资源
      最近更新 更多