Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
123
rated 0 times [  124] [ 1]  / answers: 1 / hits: 122481  / 15 Years ago, mon, august 17, 2009, 12:00:00

I know this is probably a simple question, but I'm attempting a tweak in a plugin & js is not my expertise and I got stumped on how to do the following:



I have an array that can contain a number of values ($fruit) depending on what a user has entered. I want to add another variable to the array that isn't determined by manual input.



I know push should apply here but it doesn't seem to work, why does the following syntax not work?



var veggies = carrot;
var fruitvegbasket = $('#fruit').val();
fruitvegbasket.push(veggies);





update:
I got it working doing this:



var fruit = $('#fruit').val();
var veggies = carrot;
fruitvegbasket = new Array();
fruitvegbasket.push(fruit+,+veggies);


not sure that's the best way to do it, but it works. thanks all!


More From » jquery

 Answers
68

Off the top of my head I think it should be done like this:



var veggies = carrot;
var fruitvegbasket = [];
fruitvegbasket.push(veggies);

[#98899] Thursday, August 13, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
osvaldo

Total Points: 102
Total Questions: 95
Total Answers: 102

Location: Fiji
Member since Wed, Jul 14, 2021
3 Years ago
;