javascript - Why is my array returning empty? -


this question has answer here:

var array= ["a", "b", "c", "d"]  var finalarray= array.slice(2,2);  console.log(finalarray);

this returns:

finalarray=[] 

i return:

finalarray=["c","d"] 

the first argument index @ begin extraction, , second 1 index before end extraction. so, last 2 elements (indexes 2 , 3), need this:

var array= ["a", "b", "c", "d"]  var finalarray = array.slice(2, 4); // or slice(2), since 4 length of array    console.log(finalarray);

more info on array.prototype.slice() available in mdn documentation.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -