I have an array with about 20 elements, and I need to do a few if statements while looping through this array and I need help in creating this if statement in the sense that i need to be able to search if the string contains some text in an efficient way that won’t hang up the whole app.
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
}
}
i am using pure javascript, no jquery or other frameworks.
thank you very much in advance for your help.
How about
This will just check if the word ‘GB’ is contained in the string. If it is, we’re sure it’s 1GB, 2GB, etc. If it’s not, we’re probably talking in MB, since Terabytes of RAM is not used in machines yet.
Offcourse this depends on what the possible choices of RAM are. Do they come from a (finite) list, or can the users type them themselves?