Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>String Manipulation</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. // STRING MANIPULATION:
  12.  
  13. // To alter a string by property method or concatenation.
  14.  
  15. // To join two strings by concatenation with the + operator.
  16. var join = 'Hi' + ' my name' + ' is';
  17. console.log(join);
  18.  
  19. // To split a string into an array of strings is with the split() method.
  20. var split = 'Hello';
  21. console.log(split.split('')); // split string "Hello" in to an array of strings
  22.  
  23. // To join an array of strings into a string is with the join() method.
  24. var array = ['h', 'e', 'l', 'l', 'o']; // array of strings
  25. console.log(array.join('')); // join strings of array at ''.
  26.  
  27. // To splice an array and join another element is to use the splice method.
  28. var array = ['apples', 'oranges', 'lemons', 'bananas'];
  29. array.splice(2, 1, 'peaches'); //removed lemons at index [2], removed one element, replaced
  30. // with peaches
  31. console.log(array);
  32. </script>
  33.  
  34.  
  35.  
  36. <script id="jsbin-source-javascript" type="text/javascript">// STRING MANIPULATION:
  37.  
  38. // To alter a string by property method or concatenation.
  39.  
  40. // To join two strings by concatenation with the + operator.
  41. var join = 'Hi' + ' my name' + ' is';
  42. console.log(join);
  43.  
  44. // To split a string into an array of strings is with the split() method.
  45. var split = 'Hello';
  46. console.log(split.split('')); // split string "Hello" in to an array of strings
  47.  
  48. // To join an array of strings into a string is with the join() method.
  49. var array = ['h', 'e', 'l', 'l', 'o']; // array of strings
  50. console.log(array.join('')); // join strings of array at ''.
  51.  
  52. // To splice an array and join another element is to use the splice method.
  53. var array = ['apples', 'oranges', 'lemons', 'bananas'];
  54. array.splice(2, 1, 'peaches'); //removed lemons at index [2], removed one element, replaced
  55. // with peaches
  56. console.log(array);
  57.  
  58. </script></body>
  59. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement