javascript - using .slice method on an array -


I'm practicing the array of JavaScript Koan and I'm not fully understanding why these answers are correct. I have added my beliefs below, if someone can explain to me / tell me that I am wrong:

  it should "slice arrays", function () {var array = [ Excerpt ([]];   

Why do so Will not the least piece "jelly" begin with piece 3, how does the cut of 0 change it empty?

  Hope (array.slice (3, 100)) .toEqual (["jelly"]);   

If cut off If the index is beyond the current in the array, does it mean that all the indexes starting from 3 until the end of a new array array created from slices?

  Expect (array.slice (5, 1)). ToEqual ([undefined];   

Will this always be undefined if the start index is not present in the array?

 });    

The second argument is that App er is connected to a piece

e Think

from array.slice (lowest index, highest index) .

When you slide from index 3 to index 100, then an item (in your case), which has an index; Gt; = 3 more & lt; 100, then you get an array with one item when you try to take a piece from index 3 to index 0, then there can not be any such thing as index & gt; = 3 more & lt; 0, then you will get an empty array.

- Edit -

In addition, array.slice () should never be undefined. It is one of the advantages of using it. If there is no matching value in the array, then you can only get back an empty array. Even if you call var a = new array () and do not add any value for it, then call a.slice (0,1) will give you only an empty space, the array will also return an array of empty slices from the outside of the array range. a.slice (250) will be [] , while a [250] will be undefined.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -