var dot = String(str).indexOf(".");
if(dot != -1){
var newStr = String(str).substring(dot+1,str);
console.log(newStr.length)...
yekong
2年前 (2022-06-22) 1086℃
1喜欢
type2.spotMsg = type2.spotMsg.replace(/ /g, "<br>")
type2.spotMsg = type2.spotMsg.replace(/\s/g, "<br>")
...
yekong
2年前 (2022-06-19) 735℃
0喜欢
不包含换行符
.*?
例:
亲爱.*?是
包含换行符
[\s\S]+
例:
作者有话[\s\S]+继续努力的
...
yekong
2年前 (2022-06-09) 833℃
1喜欢
?.
可选链操作符( ?. )
const obj = {hh: 'xxx'}
let res = obj?.data?.list
console.log(res) // undefined
console.log(obj?.hh?.length) //3
console.l...
yekong
2年前 (2022-06-08) 815℃
0喜欢
图片base64
var base64data = await that.imgToBase64(key)
listdata.fileBase64 = base64data.replace(/^data:image\/\w+;base64,/, ""...
yekong
2年前 (2022-06-07) 2453℃
2喜欢
手机使用gps定位获取到的经纬度,在高德地图上渲染后会有偏差,所以需要转换一下才可以用。
gps
var GPS = {
PI: 3.14159265358979324,
x_pi: 3.14159265358979324 * 3000.0 / 180.0,
tra...
yekong
2年前 (2022-06-05) 1100℃
0喜欢
for…in…
var obj = {'0':'a', '1':'b', '2':'c'};
for(let i in obj){
console.log(i,":",obj[i]);//{0:a,1:b,2:c}
}
Object.keys
var...
yekong
2年前 (2022-06-04) 871℃
0喜欢
登录页面有个要求,根据接口返回的数据依次判断类型,1-4,有1就先跳转到1,依次进行判断,一开始用的是if的判断形式,在做代码精简时,又想到了用循环的方式forEach。类型少的时候用if和forEach都可以,当类型多的时候,forEach代码要更精简一些。
if
if (th...
yekong
2年前 (2022-05-20) 1069℃
0喜欢
方法封装
export default function base64ToBlob(base64Data) {
var byteString
if (base64Data.split(',')[0].indexOf('base64') >= 0) {
byt...
yekong
2年前 (2022-05-17) 1011℃
0喜欢
js 将数据转换为字符串的另类方法,直接使用加号(+)拼接一个空字符串("")
console.log(123 + ''); // '123'
console.log([1, 2, 3] + ''); // '1,2,3'
console.log(tr...
yekong
2年前 (2022-05-17) 821℃
0喜欢