我正在尝试在 array.find 中实现可选链接。看下面的代码片段我有以下三种情况
但根据第 3 种情况,如果键值为 false,则取第 2 个
let array = [{
id: 1,
key: false
}, {
id: 2,
key: true
}]
let key =
array && array.length ?
array.find(
(item) => item.id === 1
)?.key || "empty as true value" :
"by default true";
console.log(key)Run Code Online (Sandbox Code Playgroud)
我的输入就像
var resources = ["user-john","user-doe", "students-Milan"];
Run Code Online (Sandbox Code Playgroud)
我正在尝试获得如下所示的对象输出,
{
user: ["john", "doe"],
students: ["Milan"]
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么
var resources = ["user-john","user-doe", "students-Milan"];
Run Code Online (Sandbox Code Playgroud)
我有一个对象,其中数据是对象的数组,在数据对象内部,我有一个用户属性,它是一个数组。
我需要将所有用户都放在一个阵列中。我已经使用map和编写过concat。
有什么办法可以使我有更好的解决方案,还是正确的?
请参见下面的代码段。
var response = {data: [{users: [1,2,3]}, {users: [4,5,6]}]}
var users = response.data.map(o => o.users)
const usersCollection = [].concat(...users)
console.log(usersCollection)Run Code Online (Sandbox Code Playgroud)
我试图覆盖react select options div的css,所以在最新的react-select v2中,我们可以将它作为样式传递
<Select
styles={{
option: (provided) => ({
...provided,
backgroundColor: '#fff',
border: null, // tried border: 'none'
boxShadow: null, // tried border: 'none'
outline: 0
}),
}}
/>;
Run Code Online (Sandbox Code Playgroud)
我正在尝试删除边框,尝试使用上面的代码片段,但边框和阴影保持不变
另外,当单击选择时,我需要在单击时覆盖蓝色背景
我怎样才能做到这一点
如何通过避开第一个字符串的第一个空格将下面的字符串拆分为必需的数组.
下面是示例片段,我试图用空格分割它,但是因为第一个项目1本身有空格.我怎样才能避免它并将其视为单个元素.
const data = "Item 1 10 200"
// required format [item 1, 10, 200]
// what i tried is
const implemented = data.split(" ")
console.log(implemented)Run Code Online (Sandbox Code Playgroud)
我有一个下面的查询,我需要DISTINCT ON从联合结果中做一个allowed_id 列,这在 PostgreSQL 中是可能的。我读过 Snowflake 使用类似的 PostgreSQL 但DISTINCT ON没有用。
select distinct on (allowed_id), * from (
select listagg(distinct id) as allowed_id, count (people) as totalpeople ,max(score) as maxscore , min(score) as minscore, 'n' as type from tableA
where userid = 123
union
select listagg(distinct id) as allowed_id, count (people) as totalpeople, max(elscore) as maxscore , min(elscore) as minscore, 'o' as type from tableB
where userid = 123
union
select listagg(distinct id) as allowed_id, null, null …Run Code Online (Sandbox Code Playgroud)