首页 > 解决方案 > 如何在对象中使用 Javascript url 键

问题描述

我有以下对象

websites=
{
"https://google.com": "google",
"https://wix.com/myprofile":"wix",
"https://stackoverflow.com": "stackoverflow"
}

如何使用 javascript 访问值(google、wix、stackoverflow)

标签: javascript

解决方案


您可以通过以下方式访问这些值Object[key]

let websites=
{
"https://google.com": "google",
"https://wix.com/myprofile":"wix",
"https://stackoverflow.com": "stackoverflow"
};

console.log(websites['https://google.com']);


推荐阅读