javascript - Why won't slice work? -
I'm new to JavaScript, and I'm trying to write Chrome extensions.
For expansions, if the user input a string, then I want to cut the first two characters.
Currently, I have:
if (text.charAt (0) == '/') {text.slice (0,2); Chrome.tabs.create ({url: "Private URL" + Text}); }
But that does not work, nothing is cut off. I think there is something wrong in some style, because I am still learning Any help is appreciated
The slice does not work in "place", but returns the value:
var text = "Hello World"; Console.log (text.slice (0,2)); // that console.log (text); // Hello World (unchanged!)
You must specify it in the variable like this:
text = text.slice (0,2);
In addition, from your question, it seems that you are trying to remove the first two letters. This will be
var text = "Hello World"; Text = text.slice (2); // "llow world" will be
Comments
Post a Comment