0

I need to append the values of fStr1 to some variable.This is my code.

     var myCars=new Array();
   for(i=0;i<companyLength;i++)
   {
     var othercompanies=new Array();
     othercompanies=companyrealObj[i].innerHTML;
     var fStr=othercompanies.split(">");
     var hreflink=fStr[0].split("\"");
     var fStr1=fStr[1].split("<");


     obj['name'+companyLength] =fStr1[0] ;
     myCars.append(fStr1[0]);


   } 

   alert(myCars);

here let say the companyLength=2 then the loop will be executed for 2 times.fStr1[0] will contain two values.Let say Hello1 and Hello2. I am appending the fStr1 to the myCars.But the problem is when I print the myCars it contain Hello2 only.Can anyone help me how to append the values of fStr1[0] to myCars.

2
  • Please format your question properly. Commented Feb 28, 2012 at 8:50
  • 1
    WHy are you asking same thing , you already posted similar tiype of stuff on stackoverflow.com/questions/9477879/… Commented Feb 28, 2012 at 9:11

2 Answers 2

2

you can use

myCars[]=fStr1[0];
Sign up to request clarification or add additional context in comments.

Comments

0

I think the function you're looking for is .push() so your code to append to the array should be:

myCars.push(fStr1[0]);

1 Comment

Using the sam_13's answer will be faster because it doesn't have to call a function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.