forked from HackYourFuture/JavaScript1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString_Array.js
More file actions
27 lines (22 loc) · 837 Bytes
/
String_Array.js
File metadata and controls
27 lines (22 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//javascript week2
//String
let myString = "hello,this,is,a,difficult,to,read,sentence";
console.log(myString);
console.log(myString.length);
let myNewString=myString.replace(/,/g," ");
console.log(myNewString);
//Array
favoriteAnimals = ['blowfish', 'capricorn', 'giraffe'];
console.log(favoriteAnimals);
favoriteAnimals.push('turtle');
console.log(favoriteAnimals);
favoriteAnimals.splice(1,0,'meerkat');
console.log(' I think the new value of the array is between blowfish and capricon.');
console.log(favoriteAnimals);
console.log('Array has the length of: ' + favoriteAnimals.length);
favoriteAnimals.splice(3,1);
console.log(favoriteAnimals);
var faIndex=favoriteAnimals.indexOf('meerkat');
console.log('The item you are looking for is at Index: ' + faIndex);
favoriteAnimals.splice(faIndex,1);
console.log(favoriteAnimals);