Brandon Benefield
Brandon Benefield

Reputation: 1672

JavaScript: Long list of properties alternatives

I have an object that already contains a pretty long list of properties and it's only going to grow. I'm looking for an alternative to just simply adding a new property every time one is needed but I'm not sure there is an alternative that is not only developer friendly, but non-tech savvy users can easily make changes/additions.

I've created a small version of my script that should explain what's going on.

const titles = {
  fr: 'Some text in french',
  fi: 'Some text in finnish'
  // tons more properties
}

const locale = window.location.url.split('/')[3]  // determines locale to use
const titleElement = document.querySelector('.title')
titleElement.innerText = titles[locale] | 'Some text in english'  // sets the titles text

Edit

Some context would be helpful.

Upvotes: 0

Views: 122

Answers (1)

Code-Apprentice
Code-Apprentice

Reputation: 83537

"non-tech savvy users" should not be required to edit code. Instead, you should provide a way for them to enter data into your webapp and then store it more permanently on a server. Then the webapp reads that data when it is requested and does something with it.

Upvotes: 5

Related Questions