Skip to content

Commit b5380dc

Browse files
committed
对象和面向对象编程 2
1 parent 1c6de81 commit b5380dc

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎JSDataStructures/2.3.1.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//indexOf() use nodejs
88

99

10-
var names = ["Divid","Cynthia","Raymond","Clayton","Jennifer"];
10+
var names = ["abcbc","Divid","Cynthia","Raymond","Clayton","Divid","Jennifer"];
1111
//putstr("Enter a name to seacr for:");
1212

1313
//var name = readlin();
@@ -28,3 +28,11 @@ rl.question("What do you think of Node.js? ", function(answer) {
2828
}
2929
rl.close();
3030
});
31+
32+
// lastIndexOf()
33+
var name = "Divid";
34+
var firstpos = names.indexOf(name)
35+
var lastPos = names.lastIndexOf(name)
36+
37+
console.log("first found" + name + "at position " + firstpos)
38+
console.log("Last found "+ name +'at postion ' + lastPos)

‎JSDataStructures/2.3.2.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Created by chao on 15/9/30.
3+
*/
4+
5+
var names = ["abcbc","Divid","Cynthia","Raymond","Clayton","Divid","Jennifer"];
6+
7+
var namestr = names.join();
8+
9+
console.log(namestr)
10+
11+
namestr = names.toString()
12+
13+
console.log(namestr)
14+
15+
// print -->toString()
16+
console.log(names)

0 commit comments

Comments
 (0)