Check if value exists in the array (AngularJS)

This question already has an answer here: How do I check if an array includes an object in JavaScript? 40 answers You could use indexOf function. if(list.indexOf(createItem.artNr) !== -1) { $scope.message = 'artNr already exists!'; } More about indexOf: http://www.w3schools.com/jsref/jsref_indexof_array.asp https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects

检查数组中是否存在值(AngularJS)

这个问题在这里已经有了答案: 如何检查数组是否包含JavaScript中的对象? 40个答案 你可以使用indexOf函数。 if(list.indexOf(createItem.artNr) !== -1) { $scope.message = 'artNr already exists!'; } 关于indexOf的更多信息: http://www.w3schools.com/jsref/jsref_indexof_array.asp https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf 你可以使用indexOf(

Test for value in Javascript Array

This question already has an answer here: Shorten JS if or statement [duplicate] 5 answers How do I check if an array includes an object in JavaScript? 40 answers 使用indexOf来查看x是否在数组中。 if([1,2].indexOf(x) !== -1) 尝试使用数组,然后使用.indexOf() 。 var myNumbers = [1,2]; var foo = 4; var bar = 1; var exists = (myNumbers.indexOf(bar) > -1); //true var notExists = (myNumbe

测试Javascript数组中的值

这个问题在这里已经有了答案: 缩短JS if或statement [重复] 5个答案 如何检查数组是否包含JavaScript中的对象? 40个答案 使用indexOf来查看x是否在数组中。 if([1,2].indexOf(x) !== -1) 尝试使用数组,然后使用.indexOf() 。 var myNumbers = [1,2]; var foo = 4; var bar = 1; var exists = (myNumbers.indexOf(bar) > -1); //true var notExists = (myNumbers.indexOf(foo) > -1); //false 使用Array .inc

Jquery, checking if a value exists in array or not

This question already has an answer here: How do I check if an array includes an object in JavaScript? 40 answers If you want to do it using .map() or just want to know how it works you can do it like this: var added=false; $.map(arr, function(elementOfArray, indexInArray) { if (elementOfArray.id == productID) { elementOfArray.price = productPrice; added = true; } } if (!added) {

jquery,检查数组中是否存在一个值

这个问题在这里已经有了答案: 如何检查数组是否包含JavaScript中的对象? 40个答案 如果你想用.map()来做,或者只是想知道它是如何工作的,你可以这样做: var added=false; $.map(arr, function(elementOfArray, indexInArray) { if (elementOfArray.id == productID) { elementOfArray.price = productPrice; added = true; } } if (!added) { arr.push({id: productID, price: productPrice}) } 该函数分别

How to determine if object is in array

This question already has an answer here: How do I check if an array includes an object in JavaScript? 40 answers Use something like this: function containsObject(obj, list) { var i; for (i = 0; i < list.length; i++) { if (list[i] === obj) { return true; } } return false; } In this case, containsObject(car4, carBrands) is true. Remove the ca

如何确定对象是否在数组中

这个问题在这里已经有了答案: 如何检查数组是否包含JavaScript中的对象? 40个答案 使用这样的东西: function containsObject(obj, list) { var i; for (i = 0; i < list.length; i++) { if (list[i] === obj) { return true; } } return false; } 在这种情况下, containsObject(car4, carBrands)是真的。 删除carBrands.push(car4); 调用,它将返回false而不是。

How to check if a string array contains one string in JavaScript?

This question already has an answer here: How do I check if an array includes an object in JavaScript? 40 answers There is an indexOf method that all arrays have (except Internet Explorer 8 and below) that will return the index of an element in the array, or -1 if it's not in the array: if (yourArray.indexOf("someString") > -1) { //In the array! } else { //Not in the array }

如何检查一个字符串数组是否包含JavaScript中的一个字符串?

这个问题在这里已经有了答案: 如何检查数组是否包含JavaScript中的对象? 40个答案 有一个indexOf方法,所有数组都有(除了Internet Explorer 8和更低版本),它将返回数组中元素的索引,如果它不在数组中,则返回-1: if (yourArray.indexOf("someString") > -1) { //In the array! } else { //Not in the array } 如果您需要支持旧的IE浏览器,则可以使用MDN文章中的代码来填充此方法。 您可以使用indexO

Check if an element is present in an array

This question already has an answer here: How do I check if an array includes an object in JavaScript? 40 answers ECMAScript 2016 incorporates an includes() method for arrays that specifically solves the answer, and so is now the preferred method. (As of June 2016 you will need to use a polyfill until the method is implemented natively in all major browsers.) [1, 2, 3].includes(2); //

检查数组中是否存在元素

这个问题在这里已经有了答案: 如何检查数组是否包含JavaScript中的对象? 40个答案 ECMAScript 2016包含了专门用于解决答案的数组的includes()方法,所以现在是首选方法。 (截至2016年6月,您将需要使用polyfill,直到该方法在所有主流浏览器中本地实现。) [1, 2, 3].includes(2); // true [1, 2, 3].includes(4); // false [1, 2, 3].includes(3, 3); // false 码: function isInArray(value, array) {

Javascript Bug: set audio object controls attribute True = = False

I'm rather new to this and don't know exactly how to report a bug, but I first want to confirm it's a bug and then go on from there. But here's what I'm finding: 1) When creating an audio object controls attribute, the controls attribute will respond to a string as if it's a boolean. For Instance: <button onclick="example()">Try this</button> <script>

Javascript错误:设置音频对象控件属性True = = False

我对此并不熟悉,也不知道如何报告错误,但我首先要确认它是一个错误,然后从那里继续。 但是,这就是我发现的: 1)创建音频对象控件属性时,controls属性将响应字符串,就像它是布尔值一样。 例如: <button onclick="example()">Try this</button> <script> function example() { var aud = document.createElement("AUDIO"); aud.setAttribute("src","example.mp3"); aud.setAttribu

Get the element availability status in boolean using protractor

I am trying to get the element present status of the using 'If' condition but unfortunately i am not able to get the result as either 'true' or 'false' instead i am getting like(when element is available i am getting result as 'true' and when the element is not available i am getting error message like below) Failed: No element found using locator: By(css selecto

使用量角器以布尔值获取元素可用性状态

我试图获取使用'If'条件的元素目前的状态,但不幸的是我不能得到'true'或'false'的结果,而是我越来越喜欢(当元素可用时,我得到的结果为'true',当元素不可用时,我会收到如下所示的错误消息) 失败:找不到使用locator的元素:By(css selector,.alert-message.ng-binding.alert.alert-success) 以下是我使用的代码 describe("test 1", function () { it("testing", function () {

if statement with ! before variable

This question already has an answer here: What does an exclamation mark before a variable mean in JavaScript 2 answers ! is the plan language equivalent of 'not'. it is the shorthand way of saying if (boolval != true), notice the ! in != also means not as in not equal. So the section of code you posted pretty much just says if the timer is NOT active, activate it. The 0 is conve

如果声明与! 变量之前

这个问题在这里已经有了答案: JavaScript 2中的变量意味着什么? ! 是'不'的计划语言。 它是如果(boolval!= true)的简写方式,请注意! in!=也意味着不等于不等于。 所以你发布的代码段几乎只是说如果定时器不活动,激活它。 0在之前被转换为false! 逻辑上否定它,产生真实。 if(x)意思是“如果x是true ” if(!x)意思是“如果不是x是true ”,这与“如果x是false ”是一样的,

how boolean works in javascript

I don't understand how boolean works.In the following example what is the necessity of the line "var check=false" and how does it work?/when should I use them?what if I write "var check=true" instead?? var hits=[]; for(var n=2;n<101;n++){ var check=false; for(var i=2;i<=9;i++){ if(n%i===0 && n!=i) check=true; } if(check===

如何布尔在JavaScript中工作

我不明白boolean是如何工作的。在下面的例子中,“var check = false”的必要性是什么,它是如何工作的?/我应该什么时候使用它们?如果我写“var check = true”而不是?? var hits=[]; for(var n=2;n<101;n++){ var check=false; for(var i=2;i<=9;i++){ if(n%i===0 && n!=i) check=true; } if(check===false){ hits.push(n); } } 请解释一下布尔值。我卡在这里