答案 0 :(得分:2)
您可以使用Array.prototype.some()功能。例如:
$a = Get-Date
Write-Host $a
[datetime]$time = "05/12/2016 1:57:00 AM"
DO
{
if($a -gt $time) {break}
Write-Host "not yet time"
if($a -gt $time) {break}
}while( $a -le $time)
CLS
Write-Host "done"
答案 1 :(得分:1)
只需编写一个基本的javascript for
- 循环:
var found = false;
var toCheck = { parameters: [], title: "Apple" };
for (var i = 0; i < myArray.length; i++) {
if (myArray[i].title === toCheck.title) {
found = true;
break; // no need to search further
}
}
if (!found) {
myArray.push(toCheck);
}
答案 2 :(得分:1)
我使用underscore
执行此类操作ObjectMapper mapper = new ObjectMapper();
// Your JSON should cater your class
String jsonString = "{"header": "Food" , ................}";
//JSON from String to Object
**Ratings obj = mapper.readValue(jsonString, Ratings.class)**
使用下划线可能还有一些更简洁的方法可以做到这一点。
PS:我查看了docs文档,我看到了我提到的更简洁的方式:
_.contains(fruits, function(f) { return f.title === 'Apple';})
答案 3 :(得分:-1)
尝试 indexOf 方法: http://www.w3schools.com/jsref/jsref_indexof_array.asp
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var a = fruits.indexOf("Apple");