Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Bitwise IndexOf Shorthand in javascript

// Bitwise IndexOf Shorthand in javascript
// Longhand:
if(arr.indexOf(item) > -1) { 
  // Confirm item IS found
}

if(arr.indexOf(item) === -1) { 
  // Confirm item IS NOT found
}

// Shorthand:
if(~arr.indexOf(item)) { 
  // Confirm item IS found
}

if(!~arr.indexOf(item)) { 
  // Confirm item IS NOT found
}

// we can also use the includes() function:
if(arr.includes(item)) { 
  // Returns true if the item exists, false if it doesn't
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: express plus es6 
Javascript :: kitten ui input height multiline 
Javascript :: taylors javascript test 
Javascript :: how to get last index of array in javascript 
Javascript :: how to get random value from array in javascript 
Javascript :: Add a mirgation in sequelize 
Javascript :: Node-Red: 2Outputs 
Javascript :: errorhandler npm 
Javascript :: trigger many url calls JavaScript 
Javascript :: implement dynamic import on event handler 
Javascript :: cpprestsdk json 
Javascript :: how to trigger a function after stop writing in input text jquery event 
Javascript :: GET_FORM-VALUE 
Javascript :: how to get value from a label in javascript gtk 
Javascript :: display js variable in html without + 
Javascript :: email validation in form using javascript 
Javascript :: how to detech my cosle errors in angualr 
Javascript :: Yup validation for objects and object shape 
Javascript :: disabling first item in dropdownlist 
Javascript :: react pdf fixed property not working 
Javascript :: socket cheatsheet 
Javascript :: setstate too slow 
Javascript :: Example of String.prototype.replaceAll in es12 
Javascript :: on click disable esc button using jquery 
Javascript :: this ....object of. 
Javascript :: Replace all ocourrences in JS 
Javascript :: change color jquery css 
Javascript :: multiple all elements in array 
Javascript :: find in array and return true or false react js 
Javascript :: javascript error fix 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =