Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var array1 = ["hello", "sam", "how"];
- var emptyArray2 = [];
- array1.join(" ");
- var array1 = ["hello", "sam", "how"], result = [];
- array1.forEach(function(currentString) {
- result.push(currentString.charAt(0)); // First character
- result.push(currentString.charAt(currentString.length - 1)); //Last character
- });
- console.log(result);
- # [ 'h', 'o', 's', 'm', 'h', 'w' ]
- var array2 = ["hello", "sam", "how"].map(function(p){return p.substring(1, p.length - 1)})
- var array1 = ["hello", "sam", "how"];
- var emptyArray2 = [];
- array1.forEach(function(item){
- //item.charAt(0) will give character at start of string
- //item.charAt(item.length-1) will give character at end of string
- emptyArray2.push(item.charAt(0),item.charAt(item.length-1));
- //Array.push(..) is to append elements into the array
- });
- console.log(emptyArray2); // will print ["h","o","s","m","h","w"] in console
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement