0

Hi,
I want to insert a array variable in a another variable. I know how to get it done in php but not in JavaScript. Please advice how should I code the syntax for variable statement ?

var name[0][0]="tom";
name[0][1]=12;

statement="My name is".name[0][0]."and my age is".name[0][1]";

I searched the net and found articles on strings but could not find anything which just shows how to do this. Any help will be appreciated.

Cheers,
Vishal

3
Contributors
7
Replies
10
Views
6 Years
Discussion Span
Last Post by macgurl70
0

I did more searching and its

var name="wht ever text u want" +othervar ;

Thank you for your time.

0

The way you are showing your variables looks more like an array than simply declaring variables.

You can do this two ways:
first as heilo was showing - using the array;

var name = [];
name [0] = ("tom",12);
name [1] = ("dick",11);
name [2] = ("harry",10);

function writeName1(){
  document.write("your name is "+name[0][0]+" and you are "+name[0][1]+" years old");
}

The result will be

your name is tom and you are 12 years old.


It pulls the information from the very first array, then pulls the first element from the array, followed by the second element for the age.


for the basic variable that you were referring to later on

var name = "tom";
var age = 12;

function writeName(){
  document.write("your name is "+name+" and you are "+age+" years old.");
}

You will get the same result as the first one.

Hope this helps clarify a bit.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.