小编ace*_*ase的帖子

筛选包含数组的对象数组

这是我拥有的数组的较小版本,但结构相同

与下面的const arr,我想创建2个具有唯一值且按升序排序的新数组

const arr = [{
    tags: ['f', 'b', 'd'],
    weight: 7,
    something: 'sdfsdf'
  },
  {
    tags: ['a', 'b', 'c', 'd', 'e'],
    weight: 6,
    something: 'frddd'
  },
  {
    tags: ['f', 'c', 'e', 'a'],
    weight: 7,
    something: 'ththh'
  },
  {
    tags: ['a', 'c', 'g', 'e'],
    weight: 5,
    something: 'ghjghj'
  }
];

const finalTags = [];
const finalWeight = [];

// TODO:  find a better way to do this
arr.forEach(v => {
  if (finalWeight.indexOf(v.weight) === -1) finalWeight.push(v.weight);
  v.tags.forEach(val => {
    if …
Run Code Online (Sandbox Code Playgroud)

javascript arrays sorting ecmascript-6

6
推荐指数
1
解决办法
80
查看次数

为 React 生成 useState 的 VSCode 用户片段?

我正在尝试创建一个 VS 代码用户片段 useState()

目前我有

  "use state": {
    "prefix": "us",
    "body": [
      "const [$1, set${1/(.*)/${1:/upcase}/}] = useState($2);",
      "$3"
    ],
    "description": "creates use state"
  },
Run Code Online (Sandbox Code Playgroud)

当我在 $1(位置 1)输入 'foo' 时,我得到:

const [foo, setFOO] as useState()
Run Code Online (Sandbox Code Playgroud)

但是我想得到:

const [foo, setFoo] as useState()
Run Code Online (Sandbox Code Playgroud)

如何更改我的代码段以这种方式工作?

reactjs visual-studio-code vscode-snippets react-hooks

6
推荐指数
1
解决办法
888
查看次数