参考示例:interface testObject { bundleName: string action: string entities: number } @Entry @Component struct Index { @State testObj:testObject={ bundleName: 'hhh', action: 'eee', entities: 10 } @State testRecord:Record<string,string|number>={} aboutToAppear(): void { const arr = Object.keys(this.testObj); const arr1:string[]|number[] = Object.values(this.testObj); for (let i = 0; i < arr.length; i++) { this.testRecord[arr[i]]=arr1[i] } console.log(JSON.stringify(this.testRecord) ); } build() { Column(){ } } }
参考示例: