0

I am attempting to gather values of custom data attributes using each.

Here's what I have so far JSfiddle

Heres the JQ/JS

var multi = $('.till__tablepanel_table_0_row__ticket');
var myarray = [];

$.each(multi, function (index, item) {
    myarray.push( {name: 'ticket_row_num', value: $(item).data('ticket_row_num')} ); 
    myarray.push( {name: 'itemtitle', value: $(item).data('itemtitle')} );
    myarray.push( {name: 'row_quantity', value: $(item).data('row_quantity')} ); 
    myarray.push( {name: 'rowunitprice', value: $(item).data('rowunitprice')} );  
    myarray.push( {name: 'row_total', value: $(item).data('row_total')} ); 

  //  myarray.push( {name: 'measure_type_is_grams', value: $(item).data('measure_type_is_grams')} ); 

});

alert(myarray);

The issue is I am getting [object, Object] being returned, and I don't know why.

I am terribly unfamiliar with arrays in JS/JQ and I am trying to work this out to not much avail.

1
  • You can override its toString method to make it output what you want. Commented Apr 29, 2014 at 0:28

1 Answer 1

1

It is because you have an array of objects, which when converted to string gives the o/p [object, Object].. instead try alert(JSON.stringify(myarray)); - it will give a json representation of the object.

It is happening because the default toString() implementation of an object will return [object Object]

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

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.