首页 > 其他分享 >常用js 函数

常用js 函数

时间:2024-05-29 18:16:11浏览次数:13  
标签:index 常用 函数 数组 month str Date new js



清除数组空格
removeEmptyArrays(arr) { // 使用filter方法移除空数组 // isArray方法检查元素是否为数组,length属性检查数组是否为空 return arr.filter(item => Array.isArray(item) && item.length > 0); },
清除数组空null
let newArr=syy.filter(Boolean)

字符串以某个字符开始截取

 num(str){
    const index = str.indexOf('<')
   return index!==-1 ?str.substring(0,index):str;
  }

  let currentDate = new Date();//创建时间    let currentDay = currentDate.getDate();//获取当前日期是当月的第几天     // 获取该月天数             function getMonthNum(month) {                 dateList = []                 var d = new Date();                 var curMonthDays = new Date(d.getFullYear(), month || (d.getMonth() + 1), 0).getDate();                 for (let i = 0; i < curMonthDays; i++) {                     dateList.push(i + 1)                 }             }     function getDaysInMonth(year, month) {//获取日期当月的天数(年,月)                 return new Date(year, month, 0).getDate();             }

 

 

 

 

 

 

标签:index,常用,函数,数组,month,str,Date,new,js
From: https://www.cnblogs.com/7788mmhh/p/18096705

相关文章

  • js 常用
    过滤let paid=res.data.data.filter(item=>item.status==1) 排序letpaid=[{a:1,name:你好},{a:0,name:你好}] paid.sort((a,b)=>{  //return(a[a]-b[a])  return(a.a-b.a)})      深拷贝letcp=JSON.parse(JSON.stringify(o......
  • Python lambda函数
    Pythonlambda函数Python中的lambda函数,用于创建简洁的匿名函数。Lambda函数通常用于在需要函数作为参数的上下文中,以及在需要临时定义简单函数的地方。下面是一些关于lambda函数的基本知识和用法:1.lambda函数的基本语法lambdaarguments:expressionlambda关键字用于声明......
  • 损失函数代码
    这个是从代码层面,详细了解损失函数!CrossEntropyLoss importtorchimporttorch.nnasnn#实际中遇到的outputs=torch.tensor([[0.5870,0.4130],[0.6517,0.3483],[0.4455,0.5545],[0.4......
  • Git初识-常用命令
    commandsconfiggitconfig--localuser.name"<user-name>"#配置本地(当前项目)的用户名gitconfig--localuser.email"<user-email>"#配置本地(当前项目)的用户邮箱gitconfig--globaluser.name"<user-name>"#配置全局的用户名gitconfig......
  • Python截取函数
    在Python中,你可以使用切片(slice)来截取字符串、列表和其他序列类型的一部分。以下是一些常见的示例:1.**截取字符串**:```pythons="Hello,World!"substring=s[7:12] #从索引7开始到索引12(不包括12)结束print(substring) #输出:World```2.**使用负数索引截取**......
  • C++:虚表指针、虚表、虚函数和动态多态
    classBase{public:virtualvoidshow(){std::cout<<"Baseshow"<<std::endl;}};classDerived_1:publicBase{public:voidshow()override{std::cout<<"Derivedshow"<<std::endl;}};class......
  • Three.js 中的场景与相机基础
    Three.js中的场景与相机基础一、场景(Scene)在Three.js中,场景是所有3D对象存在和交互的容器。艾斯视觉作为行业ui设计与前端开发服务商很高兴能在这里与你共同探讨:它就像是一个虚拟的3D空间,我们可以在其中添加各种几何体、灯光等元素。场景提供了一个环境,让我们可以组......
  • Qt的延时函数 实现精准延时(转)
    voidQUIHelper::delay(intmsec){//这个最准/*非阻塞方式延时,现在很多人推荐的方法*/QEventLooploop;QTimer::singleShot(msec,&loop,SLOT(quit()));loop.exec();}voidQUIHelper::deferred(intmsec){//这个最准QTimertimer;timer.setTim......
  • Linux常用指令
    1.tmux常用指令tmux是一个terminalmultiplexer(终端复用器),它可以启动一系列终端会话。我们使用命令行时,打开一个终端窗口,,会话开始,执行某些命令如npmrundev,关闭此终端窗口,会话结束,npmrundev服务会话随之被关闭。有时我们希望我们运行的服务如npmrundev或者一些cd命令等......
  • oracle的排序函数以及mysql使用变量实现排序
    oracle的排序函数rank()函数:跳跃排序,如果两个第一,则后边是第3dense_rank()函数:连续排序,,再如两个第一,则后边是第2row_number()函数:连续排序,没有并列的情况createtableccx_test( coursevarchar(10), scoreint);insertintoccx_testvalues(1,70);insertintoccx_......