Hi Friends đź‘‹,
Welcome To Infinitbility! ❤️
To convert string to object key in javascript, use the basic syntax of assign value in object using dynamic keys for example obj["your_key"] = "value"
.
In the following example, we will take example string and convert it on object key.
1let obj = {id: 1, name: "infinitbility"};23let str = "domain";45obj[str] = "infinitbility.com";67console.log(obj) // {id: 1, name: 'infinitbility', domain: 'infinitbility.com'}
Today, I’m going to show you How do i convert string to object key in javascript, as above mentioned here, I’m going to use some basic syntax which can help to assign key value pair dynamically.
Let’s start today’s tutorial how do you convert string to object key in javascript?
In this example, we will do
- Take an example of object
- Take an example of string
- Use string to assign new key value pair
- Console the output
1let obj = {id: 1, name: "infinitbility"};23let str = "domain";45obj[str] = "infinitbility.com";67console.log(obj) // {id: 1, name: 'infinitbility', domain: 'infinitbility.com'}
In the above exampls, we have taken example of adding key value pair dynamically, Let’s check the output.

I hope it’s help you, All the best 👍.
Follow me on Twitter
Join our email list and get notified about new content
No worries, I respect your privacy and I will never abuse your email.
Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.