这是我拥有的数组的较小版本,但结构相同
与下面的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)我正在尝试创建一个 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)
如何更改我的代码段以这种方式工作?