Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>String Manipulation</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- // STRING MANIPULATION:
- // To alter a string by property method or concatenation.
- // To join two strings by concatenation with the + operator.
- var join = 'Hi' + ' my name' + ' is';
- console.log(join);
- // To split a string into an array of strings is with the split() method.
- var split = 'Hello';
- console.log(split.split('')); // split string "Hello" in to an array of strings
- // To join an array of strings into a string is with the join() method.
- var array = ['h', 'e', 'l', 'l', 'o']; // array of strings
- console.log(array.join('')); // join strings of array at ''.
- // To splice an array and join another element is to use the splice method.
- var array = ['apples', 'oranges', 'lemons', 'bananas'];
- array.splice(2, 1, 'peaches'); //removed lemons at index [2], removed one element, replaced
- // with peaches
- console.log(array);
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">// STRING MANIPULATION:
- // To alter a string by property method or concatenation.
- // To join two strings by concatenation with the + operator.
- var join = 'Hi' + ' my name' + ' is';
- console.log(join);
- // To split a string into an array of strings is with the split() method.
- var split = 'Hello';
- console.log(split.split('')); // split string "Hello" in to an array of strings
- // To join an array of strings into a string is with the join() method.
- var array = ['h', 'e', 'l', 'l', 'o']; // array of strings
- console.log(array.join('')); // join strings of array at ''.
- // To splice an array and join another element is to use the splice method.
- var array = ['apples', 'oranges', 'lemons', 'bananas'];
- array.splice(2, 1, 'peaches'); //removed lemons at index [2], removed one element, replaced
- // with peaches
- console.log(array);
- </script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement