Javascript&jquery.string object. Number object. Math Object

Source: Internet
Author: User

String object. Number object. Math Object

String Object

The properties and methods of a string object are used to manipulate strings.

<!DOCTYPE html>

< html lang = "en" > < head >      < meta charset = "UTF-8" >      < title >Title</ title > </ head > < body > < script > var str="I like javascript "; document.write(str); document.write(‘< br >‘); // 属性长度 document.write(str.length); document.write(‘< br >‘); // 转大写 document.write(str.toUpperCase()); document.write(‘< br >‘); // 转小写 document.write(str.toLowerCase()); document.write(‘< br >‘); // 返回指定位置的字符,不包括空 document.write(str.charAt(5)); document.write(‘< br >‘); // 返回字符的位置 document.write(str.indexOf(‘a‘)); document.write(‘< br >‘); // 返回字符最后一次出现的位置 document.write(str.lastIndexOf(‘a‘)); document.write(‘< br >‘); // 从字符串中取指定范围的字符,从开始,包括空格 document.write(str.substring(0,4)); document.write(‘< br >‘); // 将字符串按分解规则分解成数组 var value=str.split(" "); document.write(value[0]); document.write(‘< br >‘); // 去年字符串开始和结尾的空格 document.write(str.trim()); document.write(‘< br >‘); // 查看和替换 document.write(str.replace(‘javascript‘,‘C++‘)); document.write(‘< br >‘); </ script > </ body > </ html >Math Object

The number object is typically used to manipulate numbers.

<!DOCTYPE html>

< html lang = "en" > < head >      < meta charset = "UTF-8" >      < title >Title</ title > </ head > < body > < div id = "info" ></ div > < script > var numberOne=12.545678; // 四舍五入 document.write(numberOne.toFixed()); document.write(‘< br >‘); // 指定有效数个数,这里指定为3 document.write(numberOne.toPrecision(3)); document.write(‘< br >‘); //以指数表示法返回该数值字符串表示形式,可以带参数指定小数位数 document.write(numberOne.toExponential(3)); document.write(‘< br >‘); </ script > </ body > </ html >Math ObjectThe math object is used for mathematical calculations, such as calculating squares, rounding, generating random numbers, and so on. <!DOCTYPE html> < html lang = "en" > < head >      < meta charset = "UTF-8" >      < title >Title</ title > </ head > < body > < script >      var numberTwo=23.344;      // 常量PI      document.write(Math.PI);      document.write(‘< br >‘);      // 生成随机数,0~1,范围从0到1以内,不包括1      document.write(Math.random());      document.write(‘< br >‘);      // 将整数,取最近并大于它当前值的数      document.write(Math.ceil(numberTwo));      document.write(‘< br >‘);      // 将整数,取最近并小于它当前值的数      document.write(Math.floor(numberTwo));      document.write(‘< br >‘);      // 四舍五入      document.write(Math.round(numberTwo));      document.write(‘< br >‘); </ script > </ body > </ html >

Javascript&jquery.string object. Number object. Math Object

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.