HarmonyOS 怎么获取某个object的hash,就像debug的时候得值都会显示一个xxx@xxx这种

HarmonyOS
2024-12-23 15:52:55
1504浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

ArkTS迁移自TypeScript,同样暂无获取hashCode的方法。

可参考链接

https://stackoverflow.com/questions/36811284/how-to-get-hash-value-of-an-object-in-typescript

提供两个可能的方案:

1.尝试使用三方库https://www.npmjs.com/package/ts-md5

Md5.hashStr(JSON.stringify(yourObject))

2.自实现hashCode方法:

export function hashCode(obj: object): number {
  let str:string = JSON.stringify(obj)
  let h: number = 0;
  for (var i = 0; i < str.length; i++) {
    h = 31 * h + str.charCodeAt(i);
  }
  return h & 0xFFFFFFFF
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
分享
微博
QQ
微信
回复
2024-12-23 18:58:27
相关问题
HarmonyOS SourceTool.xxx为undefined
814浏览 • 1回复 待解决
如何获取对象标识(Hash)
1507浏览 • 1回复 待解决
HarmonyOSobject怎么拼接成一个
1088浏览 • 1回复 待解决
如何获取应用签名证书hash
2863浏览 • 1回复 待解决
HarmonyOS navPathStack.removeByName(xxx)
768浏览 • 1回复 待解决
HarmonyOS 如何遍历一个JSON Object
891浏览 • 1回复 待解决
HarmonyOS 每次sync,libak.sohash都会
1037浏览 • 1回复 待解决