How to refer to an object knowing its name as a string?

I have the name of the object that is a string value. There is an object called the string values. For example I have the string value "one". (id = "one") Is object one (one = {two: "three"}). Need to go through id. id.two, of course is not working. How to refer to an object knowing its name in a string?

Anticipating the question, why, I will answer. Each item id has its own object. The structure is the same, data is different. ID written in the HTML and when you click on the link, we get its id and must refer to an object property of this element.
July 9th 19 at 10:12
2 answers
July 9th 19 at 10:14
If I understand correctly your question, you should know that the elements of the object can be treated as array elements. Example:
var source = {
 'one': {
 id: 1,
 name: 'Name1',
},
 'two': {
 id: 2,
 name: 'Name2',
}};

console.log(source['one']['name']);
console.log(source['two']['name']);


Return:
Name1
Name2
one = {two: ['three', 'four', 'five']}
two = {two: ['three', 'four', 'five']}
id = "#{$(this).attr('id')}" (will return one or two)
id.two[0] - does not work - Shakira.Pouro commented on July 9th 19 at 10:17
It turns out, the problem is that we pass a string value, but treated as an object - Shakira.Pouro commented on July 9th 19 at 10:20
: Why do you need separate variables one and two? Create a shared object that will contain them, and call quietly:
var objects = {
 one: {
 two: ['three', 'four', 'five']
},
 two: {
 two: ['three', 'four', 'five']
},
};

console.log(objects['one']['two'][0]);
- Korey.Quigley commented on July 9th 19 at 10:23
July 9th 19 at 10:16
A little bit complicate structure, then everything will be just:
var storage = {
 id1: {one: 1, two: 2},
 id2: {one: 1, two: 2}
}


Now forget about the dot notation and pass the property names as strings:
var one = storage["id1"]["one"];

If you really want to fundamentally keep these id-objects that can be accessed through window:
var one = window["id1"]["one"];
one = {two: ['three', 'four', 'five']}
two = {two: ['three', 'four', 'five']}
id = "#{$(this).attr('id')}" (will return one or two)
id.two[0] - does not work - Shakira.Pouro commented on July 9th 19 at 10:19
It turns out, the problem is that we pass a string value, but treated as an object - Shakira.Pouro commented on July 9th 19 at 10:22
curve the organization code you :\
but in General, you also said through globalco pull:
window[id].two[0] - Korey.Quigley commented on July 9th 19 at 10:25

Find more questions by tags CoffeeScriptJavaScriptjQuery