My goal is to store multiple values for a single key by utilizing arrays within my main object. I've been struggling with this and feeling discouraged, questioning why I thought I could accomplish it. Can someone provide guidance on the best approach to achieve this?
let mainObj = {}
const func = (str, obj) => {
mainObj[str] = [obj]
}
func('str1', {content: 'content1' } )
func('str2', {content: 'content2' } )
func('str2', {content: 'content3' } )
console.log(mainObj)
//instead of this:
{ str1: [ { content: 'content1' } ],
str2: [ { content: 'content3' } ] }
//I want this:
{
str1: [ { content: 'content1' } ],
str2: [ {content: 'content2' }, { content: 'content3' } ]
}