let a = [1,2,3,4,5,[6,7, 8, [9,[10,11,[12,[13]]]]]]
console.log(a)
// (6) [1, 2, 3, 4, 5, Array(4)]
console.log(flat(a))
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
...
JavaScript快速将Array转为Object
实现数组与对象的快速转换
首先我们来看一下正常情况下访问bar值
arr = [['bar',3],['two',6]]
// 正常访问 bar
console.log(arr[0][0]) // bar
使用新的API访问bar值 Object.fromEntries()
// ES10新的A...
JavaScript提取字符串的几种方式
第一种:
str = `"bar" and "foo" and "baz"`;
reg = /\"(.*?)\"/g
// 第一种方式
while (true) {
let a = reg.exec(str)
if (a === null) break;
console.log(a[1])
}
// 成...
JavaScript去除首尾空格
不管在哪种语言中去除字符串首尾空格都是会经常用到的
JavaScript中我们经常用的去除首尾空格方式是替换,比如:
str = ' hello world '
console.log(str.replace(/^\s+|\s+$/g, '')) // hello world
而如今ES10将会让我们更加方便的去除空格...
JavaScript中的扁平化输出
arr = [1, [2, [3, [4, 5, [6, [7, [8, [9]]]]]]]]
console.log(arr.flat(10)) // 递归的层数 ,如果指定底层数大于数组实际层数将按照数组最高层数执行
arr = [1,2,3];
console.log(arr.map(x => [x*2])) // 输出的是 [...
React时间轴
https://github.com/stephane-monnot/react-vertical-timeline
基本上手就能用
不过里面的 icon 并没有给出详细的说明
icon 用这个就好了
https://github.com/react-icons/react-icons
这个具体的库在这
https://react-icons.n...
如何在react中使用videojs组件
首先需要node安装video-react包
然后在index.html中添加以下
<link rel="stylesheet" href="https://video-react.github.io/assets/video-react.css" />
在需要使用的地方首先引入
i...
BrowserRouter与HashRouter的区别
关于BrowserRouter和HashRouter我百度了一下,看了网上说的一大堆总结了以下精华:
BrowerRouter是为老版本浏览器提供的hash路由
意思就是说在URL中会存在#号
而BrowserRouter是新浏览器H5的路由组件
不会再URL中存在#号
switch包含的部分...
如何将html字符串转换成dom元素呢?
这里要说的不是最常见的document.createElement('div')这种方式
以上这种方式太普通了就不介绍了
下面是一个字符串
str = '<div>hello<a>链接</a></div>'
我们要把它转换成dom 对象应该如何做呢?
...
如何创建一个store?
相信很多人不用store很快就忘记了
首先创建store文件夹
在文件夹中创建index.js
import { createStore } from 'redux'
imoprt reducer from './reducer'
const store = createStore(reducer)
export default...