Personally I find the best way to do this is still the good old if
statement:
var value = someArray.indexOf(3);
if (value === -1) {
value = 0;
}
More Related Contents:
- How do you use the ? : (conditional) operator in JavaScript?
- Question mark and colon in JavaScript
- Operator precedence with Javascript Ternary operator
- How to write an inline IF statement in JavaScript?
- Omitting the second expression when using the if-else shorthand
- JavaScript shorthand if statement, without the else portion
- JavaScript ‘if’ alternative [duplicate]
- Operator precedence with JavaScript’s ternary operator
- Multiple Ternary Operators
- JavaScript shorthand ternary operator
- How to add a black shadow on top of a div block with background image?
- javascript: hiding contents of key
- jQuery Ajax POST example with PHP
- Creating a textarea with auto-resize
- How to append to a file in Node?
- How to convert an Object {} to an Array [] of key-value pairs in JavaScript
- HTML button to NOT submit form
- How to load all the images from one of my folder into my web page, using Jquery/Javascript
- jquery clone form fields and increment id
- Javascript with jQuery: Click and double click on same element, different effect, one disables the other
- Iterating a JavaScript object’s properties using jQuery
- How to update DocsList to DriveApp in my code
- javascript closure immediate evaluation [duplicate]
- How do I detect when a web page is loaded?
- Simple HTML sanitizer in Javascript [closed]
- Download binary file with Axios
- Google Maps API 3 – zoom not honored
- How to select all textareas and textboxes using jQuery?
- Crop Functionality using FabricJs
- Getting width & height of an image with filereader