Javascript

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsWeb Design & DevelopmentJavascript

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old November 1st, 2011, 05:00 AM
ammu ammu is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 1 ammu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 17 sec
Reputation Power: 0
How to create variable name dynamically??

how to create variable name dynamically?
eg: if (test==1)
var test1=1
if (test==2)
var test2=2

here test1 and test2 should create dynamically.
i tried

var "test"+1.
But throws error.
Any idea?

Reply With Quote
  #2  
Old August 16th, 2016, 05:02 AM
jameswarner jameswarner is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Aug 2016
Posts: 3 jameswarner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 31 sec
Reputation Power: 0
Use dynamic variable names in JavaScript

Simple method to create dynamic verible

function foobar() {
this.a = 1;
this.b = 2;

var name = window['a']; // === undefined
alert(name);
name = this['a']; // === 1
alert(name);
}

new foobar();

Reply With Quote
  #3  
Old December 7th, 2016, 12:09 AM
dishagandhi dishagandhi is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Dec 2016
Location: Ahmedabad
Posts: 52 dishagandhi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 40 m 42 sec
Reputation Power: 2
In JavaScript (as i know) there are 2 ways by which you can create dynamic variables:
1. eval Function
2. window object

1. eval :
Code:
			var Index = 1;
			eval("var text" + Index+ "=123;");
			alert(text1);


2. window object:
Code:
			var index = 1;
			window["text" + Index] = 123;
			alert(window["text" + Index]);

Reply With Quote
Reply

Viewing: Tutorialized ForumsWeb Design & DevelopmentJavascript > How to create variable name dynamically??


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap