0

Here is my code: http://jsfiddle.net/yvonnezoe/MKfLU/9/

i would like to know what are the values stored in my array so that it is easier for me to monitor what has been pushed in and splice out from the array. i have tried different method such as using toString(),

$.each(rowArray, function(index, value){
      newHTML.push('<span>'+value+'</span>');
});
      $("#test").html(newHTML.join(" , "));

and so on... and it always give me "[object, Object]". Why so?

2 Answers 2

2

A row in your array is a set of 2 objects. You should display their values like that:

for(i=0;i<existingRows.length;i++){
    $('#test').html(existingRows[i].type + ' ' + existingRows[i].number +'<br>');
}

EDIT:

If you want to info about all rows correctly, you should use append method, because using html replaces current HTML of the element - append adds content at the end of what there actually is.

$('#test').html(''); //clear current content
for(i=0;i<existingRows.length;i++){
    $('#test').append(existingRows[i].type + ' ' + existingRows[i].number +'<br>');
}
Sign up to request clarification or add additional context in comments.

2 Comments

thank you :D +1 but it only displays the last one in the array? how can i display all elements in that array?
@yvonnezoe that's because you're replacing the content each time using html method. You should use append to add content to the end of current content. Check update in my answer.
1

Because value is an object.

Use newHTML.push('<span>'+JSON.stringify(value)+'</span>');

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.