Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. var a = ['A', 'B', 'C', 'D'];
  2.  
  3. var slicedArr = a.slice(1, 3); // slice starts from 1-index to 3-index, but not include 3-index : ['B', 'C']
  4.  
  5. console.log(a)
  6. // ["A", "B", "C", "D"] // slice doesn't change the input
  7. console.log(slicedArr)
  8. // ["B", "C"]
  9. var b = 'ABCD'
  10.  
  11. var slicedStr = b.slice(1, 3); // slice process the slice as the array
  12.  
  13. console.log(b)
  14. // "ABCD"
  15. console.log(slicedStr)
  16. // "BC"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement