一:创建对象的三种方法
//方法一 ???????people = new Object(); ???????people.name = "wyp"; ???????people.age = "22"; ???????document.write("name : " + people.name + ", age :" + people.age); ???????//方法二 ???????person = { ???????????name: "wyp", ???????????age: "22" ???????}; ???????document.write(person.name + person.age); ???????//方法三 使用函数创建对象 ????????function p(name, age) { ???????????this.name = name; ???????????this.age = age; ???????} ???????p1 = new p("wyp", 22); ???????document.write(p1.name + p1.age); //输出 wyp22
二:String 字符串 对象
???????//String 字符串对象 ???????var str = "hello world"; ???????document.write(str.length); //输出11 ???????//indexOf 查找字符串在字符串中的位置 存在返回在字符串中的位置 ???????document.write(str.indexOf("world")); //输出6 ???????document.write(str.indexOf("t")); ????//返回-1 ???????//内容匹配 match ????????document.write(str.match("world")); ??//打印出 world ???????document.write(str.match("1")); ?????//打印出 null ???????//replace 字符串替换 ???????document.write(str.replace("world","wyp")); ???????//字符串大小写转换 toUpperCase() toLowerCase ???????//split ???????var str1 = "hello|world"; ???????var s1 = str1.split("|"); ???????document.write(s1[0]); ???//输出 hello ???
js -- 对象
原文地址:https://www.cnblogs.com/wuyuwuyueping/p/9037047.html