Last active
April 12, 2022 14:48
-
-
Save wkei/08fc9a632d1b23d2b403039c43128b80 to your computer and use it in GitHub Desktop.
String & Array func
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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