如何更改对象内部的数组名称

How to change array name inside of an object

伙计们,我对 javascript 有点陌生。我有以下代码。我需要为数据对象分配一个字符串名称。我怎样才能转换这个对象

const obj= { data: [
    { name: "subject", note: "note", time: "12:30-1:30" },
    { name: "subject", note: "note", time: "12:30-1:30" },
  ],}

举个例子

const obj= { 'objectName': [
    { name: "subject", note: "note", time: "12:30-1:30" },
    { name: "subject", note: "note", time: "12:30-1:30" },
  ],}

很遗憾,您不能直接更改密钥的名称。但是你可以创建一个新的并删除旧的。

const obj= { data: [
    { name: "subject", note: "note", time: "12:30-1:30" },
    { name: "subject", note: "note", time: "12:30-1:30" },
  ]}

obj.newName = obj.data;
delete obj.data;

console.log(obj)