0

I have an 2d array created thats 50 by 2 and want to fill it with a passed array. I know the array works and the passed variables. But I can't get the passed variable to fill up the array, it just fills with plain text. Is my syntax wrong?

for (i=0; i <50; i++){
basket[i]=new Array(2); 
}

function addtobasket(itemname, itemvalue){
    basket[itemcount][itemcount]='itemname itemvalue;'  
}

TIA!

3
  • What is the expected format of how you want the data? Commented Aug 18, 2011 at 15:06
  • Just plain text. Is the syntax this: basket[itemcount][itemcount]=(itemname, itemvalue) Commented Aug 18, 2011 at 15:09
  • Well, you said it's already filling with plain text, and you want plain text, so I'm wondering what your question is. Commented Aug 18, 2011 at 15:09

2 Answers 2

2

'itemname itemvalue' will just fill the array with 'itemname itemvalue'

So you need to write:

basket[itemcount][itemcount]=itemname+' '+itemvalue;

Don't forget to put the semicolon AFTER the string.

Sign up to request clarification or add additional context in comments.

Comments

2
for (i=0; i <50; i++){
    basket[i]=new Array(2); 
}

function addtobasket(itemname, itemvalue){
    basket[itemcount][itemcount]= itemname + " " + itemvalue;  
}

I believe that's what you want, assuming you're trying to get the items into the array in the format "itemname itemvalue" as in your example code.

The reason you're currently seeing the names of the variables in your array, rather than their values, is that you're using the string literal "itemname itemvalue". Anything within a string literal - that is, inside the quotation marks - is left unchanged when the code executes.

Comments

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.