解构赋值
let arr = ['坏', 2010]// let name = arr[0]// let year = arr[1]let [name,year] = arrconsole.log(name, year)function get(){return ['坏', 2010]}let [name,year] = get();console.log(name)"use strict"[name,year] = ['坏', 2010]console.log(name) //报错 缺少声明语句let [,year] = ['坏', 2010]console.log(year)let [name,...args] = ['坏', 'fffff',2010]console.log(name)console.log(args)let [name,year=2010] = ['坏']console.log(year)function show(args){console.log(args)}show(['111',2010])
12.19
添加数组的多种操作技巧
**
let array = ["vhu","111"]array[array.length] = "cms"array[array.length] = "shop"console.log(array)依次添加let hd = ['shop','csm']array = [...array,...hd]console.log(array)推荐做法array.push('shop')console.log(array)数组的合并let array = ["vhu","111"]let hd = ['shop','csm']let length = array.push(...hd)console.log(length) //push 返回值是长度console.log(array)function rangeArray(begin,end){const array = []for(let i=begin;i<=end;i++){array.push(i)}return array;}console.log(rangeArray(1,5))
数据出栈与入栈及填充操作
let array = ['dfjf','ergr']let vars = array.pop() //删除的元素 后面 返回值是删除的元素console.log(vars)console.table(array)let vars = array.shift() //删除的元素 前面 返回值是删除的元素let length = array.unshift('doraemon') //往数组前面添加console.log(length) //返回值是数组的长度console.log(Array(5).fill('初')) 填充元素console.log([1,2,3,4].fill('初',1,2)) // [1, "初", 3, 4]
splice与slice实现数组的增删改查
**
slice 原数组是不改变的splice 原数组是会改变的 相当于从原数组中拿出来let arr = [1,2,3,4,5]let hd = arr.splice(0,2)console.log(hd)console.log(arr)let arr = [1,2,3,4,5]arr.splice(1,1,'chu')console.log(arr)
数组移动函数实例
function move(array,from,to){if(from<0 || to>=array.length){console.error('参数错误')return;}const newArray = [...array]let item = newArray.splice(from,1)console.log(item)newArray.splice(to,0,...item)return newArray;}let array = [1,2,3,4]console.log(move(array,-11,3))
清空数组的多种处理方式
let hd = [1,2,3,4,5]// hd = []// hd.length = 0// hd.splice(0,hd.length)// while(hd.pop()){}console.log(hd)两种有差别 引用的原因
数组的拆分与合并操作
let str = 'hdsd,dshddj';let hd = str.split(",")console.log(hd)console.log(hd.join("-"))let arr = ['1fff','fgfgg']let hd = ['11df','fff']let cms = ['shop','cms']arr = arr.concat(hd,cms)console.log(arr)let hd = [1,2,3,4]console.log(hd.copyWithin(2,0,2))
css 实现平行四边形 等常用图形
数组相关
便签整理
this.setData 的写法
[storeList[${index}].is_focus]:false
小程序中 input 框中验证是不是手机号
文字超出隐藏
微信小程序中去除 button样式
.button{
background-color:transparent;
}
.button::after {
border: 0;
}
小程序中 选择优惠券使用的设计逻辑
12.19
css 实现平行四边形 等常用图形
数组相关
便签整理
this.setData 的写法
[storeList[${index}].is_focus]:false
小程序中 input 框中验证是不是手机号
文字超出隐藏
微信小程序中去除 button样式
.button{
background-color:transparent;
}
.button::after {
border: 0;
}
12.20
加载全部的样式的书写
小程序 之弹出文字的封装
如何判断一个对象中的值没有 或者对象是空的
图片上传相关 上传多张图片的一些整合
小程序复制时候弹窗图像 去除
String对象中的split()方法
常见场景 将图片字符串转化为数组
取消状态的局部设置
// 局部设置状态
‘orderInfo.store.is_focus’:false
页面的处理 有nav点击的 没nav点击的
小程序中实现点击标签 多选
给数组中添加一个属性
https://blog.csdn.net/ChibiMarukoChan/article/details/88816892
https://blog.csdn.net/u010002184/article/details/83031681
arr.map((item,index)=>{
item.isSelect=false
})
参考文章
https://blog.csdn.net/baidu_39195199/article/details/85790220
新数组:array;
原数组:list;
给原数组list的对象加一个名为indexNum的属性,属性值为str
let array = [];
let list = [{name:’aa’,age:11},{name:’bb’,age:22},{name:’cc’,age:33},];
list.map((item,index)=>{
array.push(
Object.assign({},item,{indexNum:’str’})
)
});
console.log(123,array);
}
根据数组的相同属性重新组成一个新数组
