Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to pass an arbitrary amount of arrays from my javascript to a php file with json through ajax, the problem word is arbitrary, assume following allmost-development-code

var arrayContaingAll;

$("li", "#list").each(function()
{
  var a = array( $(".name",this).val(), $(".unit",this).val(), $(".amount", this).val() );
  arrayContainingAll[] = a;
});

however, the [] functionality on an array does not work for me, how would i go around implementing such feature?

Yes, i know PHP damaged me thinking that way

share|improve this question

2 Answers

up vote 4 down vote accepted
arrayContainingAll.push(a); //equavalent in JavaScript to PHP's arrayContainingAll[] = a;
share|improve this answer
var arrayContaingAll=[];

$("li", "#list").each(function()
{
  var tempArray=[];
  tempArray.push($(".name",this).val());
  tempArray.push($(".unit",this).val());
  tempArray.push($(".amount",this).val());
  arrayContainingAll.push(tempArray);
});

//arrayContaingAll is ready

//to optimize ur code you may cache li like this inside each

var li= $(this);
tempArray.push(li.find('class_Name'));
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.