JavaScript Day_05

JavaScript Day_05

1.数组的定义

new Array(参数,参数):只有一个数字参数时时数组的长度

var arr=new Array();//定义一个空数组
var arr=new Array(10);//定义一个有十个元素的数组,没有赋值
2.遍历数组

普通for循环

for(var i=0;i<5;i++){
	console.log(arr[i])
}

for in遍历:用于遍历数组或对象

for(var i in arr){
    console.log(arr[i])
}
3.数组中的常用函数
栈方法 push()、pop() (先进后出)

push() : 接受任意数量的参数,并逐个添加到数组的末尾,返回修改之后的数组长度

pop():从数组末尾移除最后一个元素,减少数组的length值,返回被移除的元素

队列方法 push()、shift()、unshift() (先进先出)

队列在数组的末端添加元素,在数组的前端移除元素

shift():从数组前端移除一个元素

unshift():从数组前添加一个或多个元素

4.数组操作的方法

concat() 追加数据,创建一个新数组,不改变原数组

slice() 不改变原数组,将原数组里的指定区域截取出来

splice() 截取原数组中指定的数据,会改变原数组

reverse 反转,将数组倒序排列,会影响原来的数组

sort 将数组按照ascii码排列,会影响原来的数组

join 连接方法 将数组里的元素按照设置的连接符进行连接,不会改变原数组

indexOf 查找数组元素的方法,没有找到返回-1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你想了解 JavaScript 实现的日历吗? JavaScript 可以通过 DOM 操作实现动态生成日历的功能。以下是一个简单的 JavaScript 日历实现示例: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>JavaScript 日历示例</title> <style> table { border-collapse: collapse; width: 100%; } th, td { text-align: center; padding: 8px; border: 1px solid black; } th { background-color: #ddd; } td { height: 80px; } .today { background-color: yellow; } </style> </head> <body> <h1>JavaScript 日历示例</h1> <table> <thead> <tr> <th>日</th> <th>一</th> <th>二</th> <th>三</th> <th>四</th> <th>五</th> <th>六</th> </tr> </thead> <tbody id="calendar-body"> </tbody> </table> <script> const date = new Date(); const year = date.getFullYear(); const month = date.getMonth() + 1; const today = date.getDate(); const daysInMonth = new Date(year, month, 0).getDate(); const firstDay = new Date(year, month - 1, 1).getDay(); const calendarBody = document.getElementById('calendar-body'); let dateCells = ''; let day = 1; for (let i = 0; i < 6; i++) { dateCells += '<tr>'; for (let j = 0; j < 7; j++) { if (i === 0 && j < firstDay) { dateCells += '<td></td>'; } else if (day > daysInMonth) { break; } else { if (day === today) { dateCells += '<td class="today">' + day + '</td>'; } else { dateCells += '<td>' + day + '</td>'; } day++; } } dateCells += '</tr>'; if (day > daysInMonth) { break; } } calendarBody.innerHTML = dateCells; </script> </body> </html> ``` 这个示例会生成当前月份的日历,可以根据需要进行修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值