Question: I'm trying to access a property of an object using a dynamic name. Is this possible?

```
const something = { bar: "Foobar!" };
const foo = 'bar';
something.foo; // The idea is to access something.bar, getting "Foobar!"

```

Answer: 
Following is an ES6 example of how you can access the property of an object using a property name that has been dynamically generated by concatenating two strings. 

```
var suffix = " name";

var person = {
    ["first" + suffix]: "Nicholas",
    ["last" + suffix]: "Zakas"
};

console.log(person["first name"]);      // "Nicholas"
console.log(person["last name"]);       // "Zakas"

```

This is called [computed property names](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Computed_property_names)
I asked a question that kinda duplicated on this topic a while back, and after excessive research, and seeing a lot of information missing that should be here, I feel I have something valuable to add to this older post.

* Firstly I want to address that there are several ways to obtain the value of a property and store it in a dynamic Variable. The first most popular, and easiest way IMHO would be:

```
let properyValue = element.style['enter-a-property'];

```

however I rarely go this route because it doesn't work on property values assigned via style-sheets. To give you an example, I'll demonstrate with a bit of pseudo code.

```
 let elem = document.getElementById('someDiv');
 let cssProp = elem.style['width'];

```

Using the code example above; if the width property of the div element that was stored in the 'elem' variable was styled in a CSS style-sheet, and not styled inside of its HTML tag, you are without a doubt going to get a return value of undefined stored inside of the cssProp variable. The undefined value occurs because in-order to get the correct value, the code written inside a CSS Style-Sheet needs to be computed in-order to get the value, therefore; you must use a method that will compute the value of the property who's value lies within the style-sheet.

* Henceforth the getComputedStyle() method!

```
function getCssProp(){
  let ele = document.getElementById("test");
  let cssProp = window.getComputedStyle(ele,null).getPropertyValue("width");
}

```

[W3Schools getComputedValue Doc](https://www.w3schools.com/jsref/jsref_getcomputedstyle.asp) This gives a good example, and lets you play with it, however, this link [Mozilla CSS getComputedValue doc](https://developer.mozilla.org/en-US/docs/Web/CSS/computed_value) talks about the getComputedValue function in detail, and should be read by any aspiring developer who isn't totally clear on this subject.

* As a side note, the getComputedValue method only gets, it does not set. This, obviously is a major downside, however there is a method that gets from CSS style-sheets, as well as sets values, though it is not standard Javascript.
The JQuery method...

```
$(selector).css(property,value)

```

...does get, and does set. It is what I use, the only downside is you got to know JQuery, but this is honestly one of the very many good reasons that every Javascript Developer should learn JQuery, it just makes life easy, and offers methods, like this one, which is not available with standard Javascript.
Hope this helps someone!!!