Skip to content

Instantly share code, notes, and snippets.

@wkei
Last active April 12, 2022 14:48
Show Gist options
  • Save wkei/08fc9a632d1b23d2b403039c43128b80 to your computer and use it in GitHub Desktop.
Save wkei/08fc9a632d1b23d2b403039c43128b80 to your computer and use it in GitHub Desktop.
String & Array func
var s = 'abcde'
// s.substr(1/*start*/, 3/*count*/) // bcd
s.substring(1/*start*/, 3/*end(not included)*/) // bc, not changed
s.slice(1/*start*/, 3/*end(not included)*/) // bc, not changed
s.slice(1,3) === s.substring(1,3)
var a = ["a", "b", "c", "d", "e"]
a.slice(1/*start*/, 3/*end(not included)*/) // ['b', 'c'], not changed
a.splice(1/*start*/, 3/*count*/) // ['b', 'c', 'd'], a become ['a', 'e']
a.splice(1/*start*/, 3/*count*/, 'x'/*inject*/) // ['b', 'c', 'd'], a become ['a', 'x', 'e']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment