Array +JSON +javascript

how r u

i need help in JSon array
Textt(Temp_J) is a function which sends items but Json arry doesn’t accept it

can u help plz

i have this code



var J={ "myMenu" : [   
{ "title": " ",  
"popMenu":[
          {"title":" ", "popMenu":[
          			  {"title":" "}
       				  ]
}
          ]
},

]};



function creat_J() // to add random items to array in JSON 
{ 

  
Temp_J =randomFromTo(min_lengthJ, max_lengthJ);//call random function to send a number 

for(var b=0;b<7;b++){ 

J.myMenu[b]={"title":Textt(Temp_J) , "popMenu":[{"title":"tt", "popMenu":[{"title":"tttt"}]}]}; 

// Textt(Temp_J) is function which send random text from other array  
alert(J.myMenu[b].title); 
}  


Can you show us the source of the “Textt()” function?

Have you tried seeing if Textt(Temp_J) actually returns a value before you try to insert it in to the JSON object?

immmm completing to my first q , i supposed have these :

var text4 = ["File", "Edit", "Help","Save", "View", "Find"];
var text5 = ["Print", "Close", "Paste","HEART","HEARS","SEARS","STARS","STARE","STORE","STONE"];

and our function is :


function Textt(num)
{

//alert(num);

   switch(num)
	{
	case 4:
 	document.write(text4[r]); 
 	 break;
	case 5:
	document.write(text5[r]); 
	 break;
	default:
	document.write("Item!");
 
	}

i want that these above array add to the Json Arry

You’re going to want to return a value from the Textt() function rather than using document.write

e.g.


function Textt(num) {
  switch(num)  {
    case 4:
      return text4[r]; 
    case 5:
      return text5[r]; 
    default:
      return "Item!"
  }  
}

Additionally, where is the variable r being set? You’ll need to make sure that it’s available in the Textt() function.

r is counter
when is called this function, it will increase 1

function Textt(num)
{
r=r+1;
}

my problem is in this line :
J.myMenu[b]={“title”:Textt(Temp_J) , “popMenu”:[{“title”:Textt(Temp_J), “popMenu”:[{“title”:Textt(Temp_J)}]}]};

how i can add item in Json array from other array

function Textt(num)
{
r=r+1;
//alert(num);

switch(num)
{
case 4:
document.write(text4[r]);
break;
case 5:
document.write(text5[r]);
break;
}

You’ll need to return the values from Textt() like I showed you in my previous post. When you do that, Textt() will, instead of writing the value to the page, output it to the array.

thank you
it works with me