javascript - Funny behaviour of Array.splice() -


i experimenting splice() method in jconsole

a = [1,2,3,4,5,6,7,8,9,10] 1,2,3,4,5,6,7,8,9,10 

here, simple array 1 10.

b = ['a','b','c'] a,b,c 

and b

a.splice(0, 2, b) 1,2 a,b,c,3,4,5,6,7,8,9,10 

when pass array b third argument of splice, mean "remove first 2 arguments of index zero, , replace them b array". i've never seen passing array splice()'s third argument (all guide pages read talk list of arguments), but, well, seems trick. [1,2] removed , [a,b,c,3,4,5,6,7,8,9,10]. build array, call c:

c = ['one','two','three'] one,two,three 

and try same:

a.splice(0, 2, c) a,b,c,3 one,two,three,4,5,6,7,8,9,10 

this time, 4 (instead of 2) elements removed [a,b,c,3] , c array added @ beginning. knows why? i'm sure solution trivial, don't right now.

array.splice not support array third parameter.
reference: https://developer.mozilla.org/en/javascript/reference/global_objects/array/splice

using firebug (or chrome's console), 1 sees happens:

a.splice(0, 2, b) > [1, 2] > [["a", "b", "c"], 3, 4, 5, 6, 7, 8, 9, 10] 

problem here jconsole, uses tostring() print out arrays, array.tostring() not print [].


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -