jquery - '[object HTMLLIElement]' when pushing one array into another -


suppose have dynamically created list items

<li>item1</li> <li>item2</li> <li>item3</li> <li>item4</li> 

all these items pushed array var itemarray= [];

the problem have array

var array2= []; 

of dynamically created 'li' pushed itemarray using itemarray.push(array2)

whenever append using following code

$('<ul/>', {     html: itemarray.join('') }).appendto('#left_div'); 

i following display

[object htmllielement] 

for items array2

when call itemarray.join(''), implicitly cast elements strings using tostring() method. discovered, returns [object htmllielement].

what should use .append(itemarray), allow array of dom elements:

$('<ul/>', {}).append(itemarray).appendto('#left_div'); 

also, looks might appending array2 wrong. want use concat() instead, allows merging 2 arrays. what's happening right makes [<li>,<li>,<li>,[<li>,<li>,<li>]], not single flat array:

itemarray = itemarray.concat(array2); 

Comments

Popular posts from this blog

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -