【发布时间】:2011-03-03 14:33:45
【问题描述】:
我有一个包含大约 20 个元素的数组,我需要在遍历这个数组时执行一些 if 语句,我需要帮助来创建这个 if 语句,因为我需要能够搜索字符串是否包含一些不会挂断整个应用程序的有效方式的文本。
var locations = [
['Maryland', 'USA', 'Pentium IV', 120, '1 GB', '15"'],
['New York', 'USA', 'Pentium IV', 40, '512 MB', '15" and 17"'],
['Frankfurt', 'Germany', 'Pentium IV', 100, '2 GB', '17"']
];
for (var i = 0; i < locations.length; i++) {
var ram = locations[4];
var monitor = locations[5];
// need help with the if statement below
if (ram < '1 GB' || monitor.startsWith("15")) {
// do something
}
}
我使用的是纯 javascript,没有 jquery 或其他框架。
非常感谢您的帮助。
【问题讨论】:
标签: javascript arrays if-statement