【发布时间】:2019-08-22 17:11:44
【问题描述】:
我收到如下回复。
[
{
id: '508',
class: 'class1',
value: '0',
profit: '2,
color: 'black'
},
{
id: '509',
class: 'class2',
value: '0',
profit: '0',
color: 'black'
},
{
id: '510',
class: 'class3',
value: '0',
profit: '0',
color: 'black'
},
{
id: '511',
class: 'class',
value: '0',
profit: '2.40',
color: 'black'
}
]
我必须检查 profit 密钥长度是否超过 2 个索引某些条件或者其他条件。
注意:如果利润的值为0,那么它只会被认为是空的。
为此,我做了如下操作。
const profitArrayLength = sortedProfitData.keys('profit').length;
console.log('profitArrayLength is', profitArrayLength);
但是,它在控制台中显示为未定义。
【问题讨论】:
-
“密钥长度”是什么意思?
-
长度是什么意思?字符串长度?检查后应该怎么做?你试过什么?请突出显示“我必须检查利润键长度是否超过2个索引其他条件。”!
-
你的意思是检查
profit是否为两位数(profit >= 10)? -
我只想检查利润键是否具有除 0 以外的真实值。并且该键值的长度是否大于 1。就是这样。
-
@NinaScholz 我试过 const profitArrayLength = sortedProfitData.keys('profit').length;显示未定义
标签: javascript arrays sorting react-native