首页 > 解决方案 > 如何将数据转换为对象或如何将属性对象与值交换

问题描述

所以,基本上,我在网上找到了一个列表(RAW),上面有所有的股票市场公司名称和相应的股票代码。

我想将此数据转换为 JavaScript 对象以使用这些信息......像这样:

const companiesList = 
{
    Apple : "AAPL",
    Amazon : "AMZN",
    Microsoft : "MSFT",
    IBM : "IBM",
    Senseonics : "SENS",
    PlugPower : "PLUG",
    ExxonMobil : "XOM"

}

// The idea is to have the companie name has the propertie and the symbol as the value.

但是,如果我只是粘贴我找到的列表,我会得到这样的:

let companiesList = 
{
A - Agilent Technologies,
AA - Alcoa,
AAC - Ares Acquisition,
AACE - Alexandria Agtech/Climate Innovation,
AACG - ATA Creativity Global,
AACO - Advancit Acquisition I,
AACP - Aeon Acquisition,
AACQ - Artius Acquisition,
AAIC - Arlington Asset Investment,
AAL - American Airlines,
AAMC - Altisource Asset Management,
AAME - Atlantic American,
AAN - The Aaron's Company,
AAOI - Applied Optoelectronics,
AAON - AAON, Inc.,
AAP - Advance Auto Parts,
AAPL - Apple,
...
}

所以,我想知道,因为这是一个大列表......如果有的话,我可以将此列表转换为第一个代码中显示的格式,而无需逐行更改它。

那将非常有用。谢谢

标签: javascriptdatabaseobject

解决方案


推荐阅读