js timer operation data object operation

Original link: http://www.cnblogs.com/gyh04541/p/7339073.html
    <script>

var id;
function start() {
if(id=undefined){
foo()
id=setInterval(foo,1000);
}
}

function foo() {
var timer=new Date().toString();
var ele=document.getElementById('time');
ele.value=timer;
}

function end() {
clearInterval(id);
id=undefined;
}
</script>

</head>
<body>

<input type="text" id="time">
<button onclick="start()"> start</button>
<button onclick="end()">end</button>




// var arrname=[11,2,33];
// console.log(arrname);
var arrname=new Array('a','v','b');//创建数组对象
console.log(arrname);//(3) ["a", "v", "b"]
console.log(typeof arrname)//返回object类型
console.log (typeof // new new var dd = the Array ( '//typestringReturns) //A


Monday ',' Tuesday '); // create an array of objects
// the console.log (dd) // (. 3) [ "A", "V", "B"]
//
// var new new CC = a Date () ; // create time objects
// console.log (cc) // Tue Aug 08 2017 14:09:03 GMT + 0800 ( China standard time )
//
// var bb = new new String ( 'the Hello world') // creating a string object
// the console.log (BB)

// new new Number.MAX_VALUE var = AA; // use the digital object to obtain the maximum number representable
// the console.log (AA)

var a = 'the Hello' ;
Console . log ( a . length ). 5 // get the length of the character from the
Console .log (typeof a );
Console .log(a.toLowerCase ()); // hello string lowercase
Console .log ( A .toUpperCase ()); // HELLO uppercase
// Alert (a.trim ())
Console .log ( A .trim ( )) // the Hello strips spaces on both sides of the string , which can be removed on both sides newline

// string search method
// the index search character
console .log ( a .charAt (. 4)) // fill index , the character acquired
console .log ( a .indexOf ( 'O' , 1)) // 2 a meaning , 1 as a parameter , according to the character , to find an index value
@ 2 is 2 the first value when the parameter is to find character string , the second is
// start looking for the specified index value , find the index value is returned ,
// not found to -1, from left to right to find
var A1 = 'hellopipp' Console .log ( A1 .lastIndexOf ( 'P' )) / / string a1 look of characters in the P, // if there is a plurality of identical characters , returns the index of the last character , // do not match , it returns -1; from right to left looking var A2 = 'Hello World Gu ! ' Console .log ( A2 .match ( ' World ' )) // [ "World", index:. 7, INPUT: "! Hello World"] Console .log (







A2 .search ( 'World' )) //. 6 to return to the first character of the matching index value

// truncate the string , taking part of the string
Console .log ( A2 .substr (2,4)); // LLO Index 4 position values also
Console .log ( A2 .substring (2,4)); // LL index 4 position is not taken , care regardless tail
Console .log ( A2 .replace ( 'LL' , 'F' ) ) // gu hefo world!
// replace , before old again , new in the
Console .log ( a2 .concat ( 'rr' )) // gu the Hello world! rr, string concatenation
Console .log ( A2 .split ( '' )) // (. 3) [ "Hello", "World", "Gu!"], according to the space division , to obtain an array
Console .log ( A2 .split ( '' ) [ 1]) // world, according to the index value
</ Script >
//        var arrname=[11,2,33];
// console.log(arrname);
var arrname=new Array('a','v','b');//创建数组对象
console.log(arrname);//(3) ["a", "v", "b"]
console.log(typeof arrname)//返回object类型

console.log(typeof a)//返回string类型
//
// var dd=new Array('周一','周二');//创建数组对象
// console.log(dd)//(3) ["a", "v", "b"]
//
// var cc=new Date();//创建时间对象
// console.log(cc)//Tue Aug 08 2017 14:09:03 GMT+0800 (中国标准时间)
//
// var bb=new String('hello world')//创建字符串对象
// console.log(bb)

// var aa=new Number.MAX_VALUE;//利用数字对象获取可表示的最大数
// console.log(aa)

var a='Hello ';

console.log(a.length)//5 获取字符从的长度
console.log(typeof a);

console.log(a.toLowerCase()) ;//hello 把字符串转为小写
console.log(a.toUpperCase());//HELLO 转为大写
// alert(a.trim())
console.log(a.trim())//Hello去掉字符串两边的空格,也可以去掉两边换行符

//字符串查询方法
//根据索引查字符
console.log(a.charAt(4))//填写索引值,获取字符
console.log(a.indexOf('o',1))//2个意思,1当一个参数时,根据字符,找索引值
// 2.2个参数时第一个值是要找的字符串,第二个是
//从指定的索引值开始找,找到就返回索引值,
//找不到就-1,从左向右找

var a1='hellopipp'
console.log(a1.lastIndexOf('p'))//在字符串a1里查找字符p,
//如果有多个相同的字符,就返回最后一个字符的索引,
//没有匹配,就返回-1; 从右向左找

var a2='hello world gu!'
console.log(a2.match('world'))//["world", index: 7, input: "hello world!"]
console.log(a2.search('world'))//6 返回匹配到第一个字符的索引值

//截断字符串,取字符串一部分
console.log(a2.substr(2,4));//llo索引4的位置也取值
console.log(a2.substring(2,4));//ll 索引4的位置不取,顾头不顾尾
console.log(a2.replace('ll','f'))//hefo world gu!
//替换,旧的再前,新的在后
console.log(a2.concat('rr'))//hello world gu!rr,字符串拼接
console.log(a2.split(' '))//(3) ["hello", "world", "gu!"],按照空格分割,得到数组
console.log(a2.split(' ')[1])//world,按照索引取值
</script>

转载于:https://www.cnblogs.com/gyh04541/p/7339073.html

Guess you like

Origin blog.csdn.net/weixin_30294709/article/details/94795607