gpt4 book ai didi

javascript - 如何使用对象数组访问 if ?

转载 作者:行者123 更新时间:2023-11-30 09:12:09 25 4
gpt4 key购买 nike

您好,我是 JS 新手,我需要测试 if。

const length = notifications.length
notifications.forEach((notification, index) => {
if (length > 1 && index < length - 1) {
toolTipText += ' '
}

也就是说我需要声明一个变量来进入if。我有这些变量,但是是错误的,我不知道如何做好

const mockPropsForComponentAlternatorAndLOW = {
notifications: [{
params: {
subType: 'ALTERNATOR'
}
},
params: {
subType: 'LOW'
}]
}

有什么建议吗?

最佳答案

您的脚本有效。只需删除一些语法错误并指向正确的引用:

mockPropsForComponentAlternatorAndLOW.notifications.length

const mockPropsForComponentAlternatorAndLOW = {
notifications: [
{
params: {
subType: 'ALTERNATOR'
}
},
{
params: {
subType: 'LOW'
}
}
]
}

const length = mockPropsForComponentAlternatorAndLOW.notifications.length

mockPropsForComponentAlternatorAndLOW.notifications.forEach((notification, index) => {
if (length > 1 && index < length - 1) {
alert('in the scope now')
// toolTipText += ' '
}
})

关于javascript - 如何使用对象数组访问 if ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57774940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com