I am trying to assign a value to a specific key in javascript named "AAPL".
However, when I assign this value, all my keys are getting assigned the same value.
My code below shows how I construct the object and assign the string value to [key].ticker.
var Underlying = [
"FB",
"AAPL"
// ,
// "AMZN",
// "NFLX",
// "GOOG",
// "TWTR",
// "BABA",
// "TSLA",
// "AMD",
// "INTC",
// "MSFT",
// "RY",
// "CM",
// "BNS",
// "TD",
// "BMO"
];
const innerobj = {
ticker: "",
bidtype: "",
asktype: "",
price: "",
size: "",
timestamp: ""
};
const obj = Underlying.reduce(
(o, key) => ({
...o,
[key]: innerobj
}),
{}
);
obj["AAPL"].ticker = "AAPL";
console.log(obj);
However, the result I get is this:
{ FB:
{ ticker: 'AAPL',
bidtype: '',
asktype: '',
price: '',
size: '',
timestamp: '' },
AAPL:
{ ticker: 'AAPL',
bidtype: '',
asktype: '',
price: '',
size: '',
timestamp: '' } }
I have tried many things. I appreciate any help or guidance. Thank you.