Javascript中常见的内置对象有哪些

 4952

javascript中常见的内置对象有Array对象、Math对象、Date对象和String对象。内置对象就是指javascript本身自带的对象。


Javascript中常见的内置对象有哪些


javascript中的内置对象其实就是指javascript本身自带的对象,并且提供了一些常用的功能而已。

常见的内置对象有四种,分别是:

Array对象:提供一个数组的模型来存储大量有序的数据。

Math对象:可以处理所有的数学运算 。

Date对象:可以处理日期和时间的存储、转化和表达。

String对象:可以处理所有的字符串的操作。

数学对象代码示例:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title></title>
  6. </head>
  7. <body>
  8.     <script>
  9.         console.log(Math);
  10.         console.log(Math.PI);//输出为π
  11.         console.log(Math.floor(1.9));//向下取整
  12.         console.log(Math.ceil(1.1));//向上取整
  13.         console.log(Math.round(4.3));//四舍五入
  14.         console.log(Math.abs(-33));//取绝对值
  15.         console.log(Math.max(1, 2, 3, 4, 5));//取最大值
  16.         console.log(Math.max.apply(null, [1, 2, 3, 4, 5]));//null表示this指针不替换
  17.         console.log(Math.min(1, 2, 3, 4, 5));//取最小值
  18.         console.log(Math.min.apply(null, [1, 2, 3, 4, 5]));
  19.         console.log(Math.sqrt(100));//开平方
  20.         console.log(Math.pow(5, 3));//幂,5的3次方
  21.         console.log(Math.sin(90 * Math.PI / 180));//正弦,弧度=角度*π/180
  22.         console.log(Math.cos(180 * Math.PI / 180));//余弦
  23.         console.log(Math.tan(90 * Math.PI / 180));//正切
  24.     </script>
  25. </body>
  26. </html>


本文网址:https://www.zztuku.com/detail-8998.html
站长图库 - Javascript中常见的内置对象有哪些
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐