我有一个像这样的数组:
const arr = [[1, 2], [3, 4], [5, 7]]
Run Code Online (Sandbox Code Playgroud)
假设我有两个数字:3和4,我如何检查这两个数字中是否有一对(无论数组中存在它的顺序?
我正在尝试从一个简单的数组中创建一个深层嵌套的 JS 对象。棘手的部分是数组中的下一项应始终添加到前一项。
假设我的数组如下所示:
const filters = [
[
{brand: {eq: 'BMW'}},
{brand: {eq: 'AUDI'}}
],
[
{year: {eq: '2019'}},
{year: {eq: '2020'}}
],
[
{country: {eq: 'CH'}},
{country: {eq: 'DE'}}
]
]
Run Code Online (Sandbox Code Playgroud)
如何获得具有该结构的对象?
query: {
and: {
or: [
{ brand: { eq: 'BMW' } },
{ brand: { eq: 'AUDI' } }
],
and: {
or: [
{ year: { eq: '2019' } },
{ year: { eq: '2020' } }
],
and: {
or: [
{ country: …Run Code Online (Sandbox Code Playgroud) 在 JavaScript 中,如何查找包含某些字母的数组元素?
例如,我怎么能确定find在下面的匹配super和phone,但不wood?
var array1 = ["super", "phone", "wood"]
find("h", "n", "e")
message.channel.send(results) // should send phone
Run Code Online (Sandbox Code Playgroud)
我在 discord.js 上做这件事,而且相当新
我有一个像这样的数组数组:
[
[ 48, 28 ], [ 36, 19 ],
[ 54, 12 ], [ 24, 12 ],
[ 30, 12 ], [ 42, 12 ],
[ 40, 10 ], [ 48, 4 ],
[ 12, 4 ], [ 18, 3 ],
[ 20, 2 ], [ 36, 1 ]
]
Run Code Online (Sandbox Code Playgroud)
我想根据每个项目的第一个值过滤重复项:item[0]。例如,对于上面的数组,我想从中删除[48, 4]and [36, 1],因为它已经包含[48, 28]and [36, 19]。预先感谢您的帮助。
有这样的字符串
str = "word 12 otherword(s) 2000 19"
Run Code Online (Sandbox Code Playgroud)
或者像这样
str = "word word 12 otherword(s) 2000 19"
Run Code Online (Sandbox Code Playgroud)
我需要将字符串一分为二,以获得这样的数组:
newstr[0] = first part of the string (即第一种情况下的“word”,第二种情况下的“word word”);
newstr[1] = rest of the string (即“12 otherword(s) 2000 19”在这两种情况下)。
我尝试使用splitand完成此操作regex,但没有成功:
str.split(/\d.*/)返回Array [ "word ", "" ]或Array [ "word word ", "" ]
而str.split(/^\D*/gm)返回Array [ "", "12 otherword(s) 2000 19" ]
你能给我一个建议吗?即使不使用splitand regex- 如果有更好/更快的(Vanilla JavaScript)解决方案。