1. find()与findIndex() find()方法,用于找出第一个符合条件的数组成员。它的参数是一个回调函数,所有数组成员依次执行该回调函数,直到找出第一个返回值为true的成员,然后返回该成员。如果没有符合条件的成员,则返回undefined。 [1, 2, 5, -1, 9].find((n) => n < 0) //找出数组中第一个小于 0 的成员 // -1 find()方法的回调函数可以接受三个参数,依次为当前的值、当前的位置和原数组。 findIndex()方法的用法与find()方法非常类似,返回第一个符合条件的数组成员的位置,如果所有成员都不符合条件,则返回-1。 [1, 2, 5, -1, 9].findIndex((n) => n < 0) //返回符合条件的值的位置(索引) // 3 2. filter() filter()方法使用指定的函数测试所有元素,并创建一个包含所有通过测试的元素的新数组。 filter 为数组中的每个元素调用一次 callback 函数,并利用所有使得 callback 返回 true 或 等价于 true 的值 的元素创建一个新数组。那些没有通过 callback 测试的元素会被跳过,不会被包含在新数组中。filter 不会改变原数组。 var arr = [10, 20, 30, 40, 50] var newArr = arr.filter(item => item > 30); console.log(newArr); //[40, 50] //数组去重 var arr = [1, 2, 2, 3, 4, 5, 5, 6, 7, 7, 8, 8, 0, 8, 6, 3, […]
View Details数组与字符串相互转换方法
toString() 将数组转换成一个字符串
toLocalString() 把数组转换成本地约定的字符串
join() 将数组元素连接起来以构建一个字符串
批量选择table 的行数 代码实现: 在<el-table >添加属性 ref = "multipleTable " , 在<el-table-colum> 添加type属性 type=" selection "
1 |
再通过一下代码就能获取已选择的行的数据;
1 |
this.$refs.multipleTable.selection |
这里的 multipleTable 是上面ref 的值; from:https://blog.csdn.net/weixin_42517975/article/details/89631128
View Details1.设置row-key
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<el-table :border="true" :highlight-current-row="true" v-loading="loading" element-loading-text="数据加载中..." element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" ref="multipleTable" :data="partList" :row-key="getRowKey" tooltip-effect="dark" style="width: 100%" @select-all="handleSelectionAll" @selection-change="handleSelectionChange"> getRowKey (row) { return row.code }, |
2.设置选择行状态 :reserve-selection=“true”
1 |
<el-table-column align="center" :reserve-selection="true" type="selection" width="55"></el-table-column> |
from:https://blog.csdn.net/weixin_43153741/article/details/104842331
View Detailsobj.concat(arrayx,arrayy); ver a = [1,2,3]; var b = [4,5]; a.concat(b);//1,2,3,4,5
View Details今天看了一下 有好几种方法 总结一下 1:array.indexOf 此方法判断数组中是否存在某个值,如果存在返回数组元素的下标,否则返回-1
1 2 3 |
let arr = ['something', 'anything', 'nothing', 'anything']; let index = arr.indexOf('nothing'); console.log(index) //结果是2 |
2. array.includes(searchElement[, fromIndex]) 此方法判断数组中是否存在某个值,如果存在返回 true,否则返回false。
1 2 3 4 5 6 7 8 9 10 11 12 |
function test(fruit) { const redFruits = ['apple', 'strawberry', 'cherry', 'cranberries']; if (redFruits.includes(fruit)) { console.log('red'); }else{ console.log('blue'); } } test('aple')//结果是red |
3. array.find(callback[, thisArg]) 返回数组中满足条件的第一个元素的值,如果没有,返回undefined
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// ---------- 元素是普通字面值 ---------- let numbers = [12, 5, 8, 130, 44]; let result = numbers.find(item => { return item > 8; }); console.log(result) # 结果: 12 // ---------- 元素是对象 ---------- let items = [ {id: 1, name: 'something'}, {id: 2, name: 'anything'}, {id: 3, name: 'nothing'}, {id: 4, name: 'anything'} ]; let item = items.find(item => { return item.id == 3; }); console.log(item) # 结果: Object { id: 3, name: "nothing" } |
4. array.findIndex(callback[, thisArg]) 返回数组中满足条件的第一个元素的索引(下标), 如果没有找到,返回-1 同第3种方法类似 from:https://www.cnblogs.com/hepengqiang/p/9822118.html
View Details