Skip to content

Instantly share code, notes, and snippets.

@zgulde
Last active March 18, 2016 20:35
Show Gist options
  • Select an option

  • Save zgulde/a7818c2081a894902835 to your computer and use it in GitHub Desktop.

Select an option

Save zgulde/a7818c2081a894902835 to your computer and use it in GitHub Desktop.

most, but not all (notably sort and reverse on arrays) methods on arrays and strings will not modify the string or array

for example

var myString = 'qwerty';
console.log(myString.split('')); // ['q','w','e','r','t','y']
console.log(myString); // 'qwerty'

myString.toUpperCase();
console.log(myString); // still 'qwerty'

to use the results of a manipulation we must store it in a variable

var myArray = myString.split('');
console.log(myString); // still 'qwerty'
console.log(myArray); // ['q','w','e','r','t','y']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment