SHARE
TWEET

Untitled

a guest Aug 12th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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"
RAW Paste Data
Top