Skip to content

Instantly share code, notes, and snippets.

@lyuehh
Created December 28, 2013 09:30
Show Gist options
  • Select an option

  • Save lyuehh/8157693 to your computer and use it in GitHub Desktop.

Select an option

Save lyuehh/8157693 to your computer and use it in GitHub Desktop.
/* global console */
var str = "hello world";
console.log("str: " + str);
console.log();
console.log("slice(3): " + str.slice(3));
console.log("substring(3): " + str.substring(3));
console.log("substr(3): " + str.substr(3));
console.log();
console.log("slice(3,7): " + str.slice(3, 7));
console.log("substring(3, 7): " + str.substring(3, 7));
console.log("substr(3, 7): " + str.substr(3, 7));
console.log();
console.log("slice(-3): " + str.slice(-3));
console.log("substring(-3): " + str.substring(-3));
console.log("substr(-3): " + str.substr(-3));
console.log();
console.log("slice(3, -4): " + str.slice(3, -4));
console.log("substring(3, -4): " + str.substring(3, -4));
console.log("substr(3, -4): " + str.substr(3, -4));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment