小小的js
//安全登陆不允许iframe嵌入
if (window.top !== window.self) {
window.top.location = window.location;
}
使用filter过滤参数
let a = [0];
a = a.filter(item => {
return item
});
console.log(a); //[] 0也会被过滤掉
let b = [0,1,2,undefined];
b = b.filter(item => {
return item
});
console.log(b);//[1, 2]
reduce谜之操作
const arr = [{id: 1,type: 'A',total: 3}, {id: 2,type: 'B',total: 5}, {id: 3,type: 'E',total: 7}];
const re = arr.reduce((sum,{total})=>{
return sum + total;
},0);
const re1 = arr.reduce((str, { id, type,total }) => {
return str + `id:${id},type:${type},total:${total};`;
}, '');
const re2 = arr.reduce((res, { id, type, total }) => {
res[id] = {
type,
total
};
return res;
}, {});
const re3 = arr.reduce((res, { id, type, total },index) => {
res[index] = type;
return res;
}, []);
console.log(re); //结果为total的累加
console.log(re1); //id:1,type:A,total:3;id:2,type:B,total:5;id:3,type:E,total:7;字符串
console.log(re2); //{1: {type: "A", total: 3}, 2: {…}, 3: {…}}
console.log(re3); //["A", "B", "E"]
const re3 = arr.reduce((
第一个参数:累加器累加回调的返回值-res,
第二个参数:数组中正在处理的元素-{ id, type, total },
第三个参数可选:当前元素的索引-index,
第四个参数可选:调用reduce()的数组-array) => {
res[index] = type;
return res;
}, []);
小小的js的更多相关文章
- 自己根据js的兼容封装了一个小小的js库
var gys = function () { } //oParent父节点 //获取所有的子元素 gys.prototype.getElementChildren = function (oPare ...
- 天地图,js 4.0 api,简单调用,高手请绕行
本文介绍使用天地图 js4.0 api,实现地图显示后台gps分布情况: 主要借用H5 GPS获取,利用天地图的背景展示: 效果图如下: 第一步,通过采集网页,手机gps数据,录入后台数据库:界面如下 ...
- 齐博x1一段不错的小js提高一点点阅读体验 计算本文阅读所需的时长
如图所示很多比较大的站点都有这样的一个小玩意 就是本文有多少字 阅读需要多少时间. 一段小小的js就可以实现,当然了php也可以功能太小了不值得做钩子或者插件自己需要的话再模板加一下吧. <sc ...
- JavaScript侧边悬浮框
<script> window.onscroll=function(){ var oDiv=document.getElementById('div1'); var scrollTop=d ...
- AngularJS 初印象------对比 Asp.net MVC
之前就早耳闻前端MVC的一些框架,微软自家的Knockout.js,google家的AngularJs,还有Backone.但未曾了解,也不解为什么前端也要这么分.这两天看了AngularJs的官方教 ...
- 【转载】IE6 PNG透明终极解决方案(打造W3Cfuns-IE6PNG最强帖)
原文地址:http://www.w3cfuns.com/thread-297-1-1.html 本文版权归W3Cfuns.com所有,转载需在文章页面明显位置以链接的方式给出原文链接,否则W3Cfun ...
- (转)jquery ajax使用及跨域访问解决办法
原文地址:***/UIweb/jquery_ajax_kuayujiejue.html 最近开发中,设计到智能手机项目,给领导做几个demo.主要是用jquery和jqeury mobile. 越来越 ...
- bootstrap-paginator 分页插件笔记
[MVC]bootstrap-paginator 分页插件笔记 bootstrap-paginator基于bootstrap框架,使用起来非常简单.官网:http://harttle.github ...
- AngularJS and Asp.net MVC
AngularJS 初印象------对比 Asp.net MVC 之前就早耳闻前端MVC的一些框架,微软自家的Knockout.js,google家的AngularJs,还有Backone.但未曾了 ...
随机推荐
- 题目1022:游船出租(hash简单应用)
问题来源 http://ac.jobdu.com/problem.php?pid=1022 问题描述 每次输入:船号(1~100) 键值(S或E) 发生时间(小时:分钟).当船号为0时,代表一天结束: ...
- Python爬取LOL英雄皮肤
Python爬取LOL英雄皮肤 Python 爬虫 一 实现分析 在官网上找到英雄皮肤的真实链接,查看多个后发现前缀相同,后面对应为英雄的ID和皮肤的ID,皮肤的ID从00开始顺序递增,而英雄ID跟 ...
- [BZOJ 4857][Jsoi2016]反质数序列
传送门 $ \color{green} {solution : } $ 因为 $ 1 $ 的个数我们最多只能选一个,所以剩下的数如果组成素数那么只有一奇一偶,显然是个二分图模型 #include &l ...
- Angular material mat-icon 资源参考_Connection
ul,li>ol { margin-bottom: 0 } dt { font-weight: 700 } dd { margin: 0 1.5em 1.5em } img { height: ...
- Comparación para 2019 Nueva Lonsdor K518S y K518ISE
Comparación para 2019 Nueva Lonsdor K518S y Lonsdor K518ISE: Igual: Capacidades de Immo y cobertura ...
- docker 把容器commit成镜像
该方法是使用docker commit 命令,其命令格式为: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] 主要参数选项包括: -a ,– ...
- 深刻理解Python中的元类(metaclass)(转)
转载地址:http://blog.jobbole.com/21351/ 另外有几点理解记录下: 创建一个实例时,有时会传入参数,这些参数会同时传入 __init__() 和 __new__(),如: ...
- 使用autoconf完成编译配置
使用过开源C/C++项目的同学们都知道,标准的编译过程已经变成了简单的三部曲:configure/make/make install, 使用起来很方便,不像平时自己写代码,要手写一堆复杂的Makefi ...
- Mac下配置maven和集成到ecclipse(Mac 10.12)
1.到官网下载maven,http://maven.apache.org/download.cgi 下载好的tar.gz包解压出来,并重命名为maven3,拷贝到/usr/local目录下 2.配置环 ...
- JS框架设计之加载器所在路径的探知一模块加载系统
1.要加载一个模块,我们需要一个URL作为加载地址,一个script作为加载媒介,但用户在require是都用ID,我们需要一个将ID转换为URL的方法,思路很简单,强加个约定,URL的合成规则是为: ...