/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Error: missing name after . operator

I get ‘Error: missing name after . operator’ when I run this script and I’m not too sure what the problem is?

[CODE]<script type=”text/javascript”>
var abbrs =
{ HTML : [ ‘HyperText Markup Language’]
, PHP: ‘Personal Home Page’
}

var somevar = “PHP”;
for( var i = 0 ; i < abbrs.[somevar].length; i++)
{
var expanded = abbrs[somevar][i];
alert( somevar + ” is short for ” + expanded );
}
</script>[/CODE]

Error: missing name after . operator

for( var i = 0 ; i < abbrs.[somevar].length; i++)

Where is the problem in this code?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@web_bertFeb 19.2009 — this should be

for( var i = 0 ; i < abbrs[somevar].length; i++)

you do not need a . when using [] to call a property or method
Copy linkTweet thisAlerts:
@FangFeb 19.2009 — abbrs[somevar].length
Copy linkTweet thisAlerts:
@happyeddieauthorFeb 19.2009 — thank you
×

Success!

Help @happyeddie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...