Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script id="jsbin-javascript">
- /*
- * Strings: Character Data
- *
- * Strings create words, phrases, etc
- * (a string of characters)
- */
- var myString = "Hello!"
- // to access the specific characters in a string:
- // value: H e l l o
- // index: 0 1 2 3 4
- // use brackets [] -> aString[index]
- var h = myString[0];
- console.log(h);
- /** OR **/
- // use the method charAt() -> aString.charAt(index)
- var e = myString.charAt(1);
- console.log(e);
- /** OR **/
- // use the method slice() -> aString.slice(index, index)
- var l = myString.slice(2,3); // starts at index 2 and ends before 3
- console.log(l);
- var loEx = myString.slice(3); // starts at index 3 and goes until the end of the string
- console.log(loEx);
- // note: can access the last character of a string by using .length
- var loEx = myString.charAt(aString.length-1);
- console.log(loEx);
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">/*
- * Strings: Character Data
- *
- * Strings create words, phrases, etc
- * (a string of characters)
- */
- var myString = "Hello!"
- // to access the specific characters in a string:
- // value: H e l l o
- // index: 0 1 2 3 4
- // use brackets [] -> aString[index]
- var h = myString[0];
- console.log(h);
- /** OR **/
- // use the method charAt() -> aString.charAt(index)
- var e = myString.charAt(1);
- console.log(e);
- /** OR **/
- // use the method slice() -> aString.slice(index, index)
- var l = myString.slice(2,3); // starts at index 2 and ends before 3
- console.log(l);
- var loEx = myString.slice(3); // starts at index 3 and goes until the end of the string
- console.log(loEx);
- // note: can access the last character of a string by using .length
- var loEx = myString.charAt(aString.length-1);
- console.log(loEx);</script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement