Leron
Leron

Reputation: 9856

JavaScript - passing string as an object property

Just FYI this code is part of ExtJS 4 script. I have a global setting which I use to show the path to the dir where my icons are. I'm making some modifications so before was:

g_settings.iconUrl

but now I need to pass a third argument property like this:

g_settings.iconUrl.docIcon

The problem I met is where I have an if statement where I check for different values:

if (extensions == 'doc'||extensions == 'docx'||extensions == 'xlsx'||extensions == 'xls)

and then I do:

extensions += 'Icon';

and I need to use:

g_settings.iconUrl.extension

when I use console.log(extensions) it's value is as expected (for example docIcon) but when I try to use it as a property it doesn't work. If I use console.log on:

console.log(g_settings.iconUrl+ '.' +extensions)

the output is [object Object].docIcon so I think I have to convert somehow extensions to object too. I'm not sure that this will solve the problem but that's what I have for now.

Any suggestions?

Thanks

Leron

Upvotes: 0

Views: 191

Answers (2)

minikomi
minikomi

Reputation: 8503

Why not just add it to the string..

console.log("g_settings.iconUrl." + examples)

Upvotes: 1

neu-rah
neu-rah

Reputation: 1693

iconURL was (and probably still is) a string, but then you added some properties... so on the assignment of .iconURL="..." you should use

iconURL.file="...";//(or other name you choose)

and latter use

.iconURL.file+"."+extensions;

Upvotes: 0

Related Questions