Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. var array1 = ["hello", "sam", "how"];
  2.  
  3. var emptyArray2 = [];
  4.  
  5. array1.join(" ");
  6.  
  7. var array1 = ["hello", "sam", "how"], result = [];
  8. array1.forEach(function(currentString) {
  9. result.push(currentString.charAt(0)); // First character
  10. result.push(currentString.charAt(currentString.length - 1)); //Last character
  11. });
  12. console.log(result);
  13. # [ 'h', 'o', 's', 'm', 'h', 'w' ]
  14.  
  15. var array2 = ["hello", "sam", "how"].map(function(p){return p.substring(1, p.length - 1)})
  16.  
  17. var array1 = ["hello", "sam", "how"];
  18.  
  19. var emptyArray2 = [];
  20.  
  21. array1.forEach(function(item){
  22. //item.charAt(0) will give character at start of string
  23. //item.charAt(item.length-1) will give character at end of string
  24. emptyArray2.push(item.charAt(0),item.charAt(item.length-1));
  25. //Array.push(..) is to append elements into the array
  26. });
  27. console.log(emptyArray2); // will print ["h","o","s","m","h","w"] in console
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement