y***@sina.com
y***@sina.com
  • 发布:2024-02-23 17:15
  • 更新:2024-02-23 17:15
  • 阅读:60

JQL更新数组的时候,数组下标可以用变量吗?该如何写?

分类:uniCloud

文档里面的说明:
更新数组时,以数组下标作为key即可,比如以下示例将数组arr内下标为1的值修改为 uniCloud

const db = uniCloud.database();  
let collection = db.collection("table1")  
let res = await collection.where({_id:'doc-id'})  
  .update({  
    arr: {  
      1: "uniCloud"  
    }  
  })

如果要更新数组下标是一个变量,是不是可以?例如要更新变量idx指定的下标的元素,示意如下:

let idx=5  
const db = uniCloud.database();  
let collection = db.collection("table1")  
let res = await collection.where({_id:'doc-id'})  
  .update({  
    arr: {  
      idx: "uniCloud"  
    }  
  })

是不是可以做到?代码该怎么写?

2024-02-23 17:15 负责人:无 分享
已邀请:

要回复问题请先登录注册