const invert = (obj) => Object.keys(obj).reduce((res, k) => Object.assign(res, { [obj[k]]: k }), {})
var t = invert({name: 'jack'}) // {jack: 'name'}
console.log(t)
const removeNullUndefined = (obj) => Object.entries(obj).reduce((a, [k, v]) => (v == null ? a : ((a[k] = v), a)), {});
var t = removeNullUndefined({name: '', age: undefined, sex: null}) // { name: '' }
console.log(t)
const hexToRgb = hex => hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (_, r, g, b) => `#${r}${r}${g}${g}${b}${b}`).substring(1).match(/.{2}/g).map((x) => parseInt(x, 16));
var t = hexToRgb('#00ffff'); // [0, 255, 255]
var t = hexToRgb('#0ff'); // [0, 255, 255]
console.log(t)
const isEqual = (...objects) => objects.every(obj => JSON.stringify(obj) === JSON.stringify(objects[0]))
isEqual({name: 'jack'}, {name: 'jack'}) // true
isEqual({name: 'jack'}, {name: 'jack1'}, {name: 'jack'}) // false
const stripHtml = (html) => new DOMParser().parseFromString(html, 'text/html').body.textContent || '';
var txt = stripHtml('ddd
test') // 'dddtest'
console.log(txt)
const strParse = (str) => JSON.parse(str.replace(/(\w+)\s*:/g, (_, p1) => `"${p1}":`).replace(/\'/g, "\""))
var obj = strParse('{"name": "jack"}')
var obj = strParse('{name: "jack"}')
console.log(obj)
jQuery(document).bind("DOMSubtreeModified",{},function(){alert(666)});
Document
- 根本英俊赢得iPhone6
- 根本英俊赢得iPhone6
- 根本英俊赢得iPhone6
- 根本英俊赢得iPhone6
var sUserAgent = navigator.userAgent.toLowerCase();
if(sUserAgent.match(/ipad/i)==“ipad”){
u.MobileSystem = IPAD;
u.System = MOBILE;
}else if(sUserAgent.match(/iphone os/i)==“iphone”){
u.MobileSystem = IPHONE;
u.System = MOBILE;
}else if(sUserAgent.match(/android/i)==“android”){
u.MobileSystem = ANDROID;
u.System = MOBILE;
}
菜鸟教程(runoob.com)
alert($scope.dataVal.replace(/(^\s*)|(\s*$)/g, "")=="") //为空 true 不为空FALSE
function patch(s, re) {//匹配出现的个数
re=new RegExp(re,"ig");//字符串转正则
return s.match(re) ? s.match(re).length : 0;
}
alert(patch(str, key)>0)
argsStr = $("#args").val(),
argsObj= eval('(' + argsStr + ')'),
< body οnblur=”this.focus();”>
空字符串""。
null。
undefined。
数字0.
数字NaN。
布尔值false;
< input οnkeydοwn=”if(event.keyCode==13)event.keyCode=9″>
取整是直接去掉小数点后的小数,而并不是采用的四省五入的计算.
var str = "123.123";
console.log(~~str);
< a href=”#” onFocus=”this.blur()”>< img src=”logo.jpg” border=0>< /a>