This is the minimum minimum:
function deleteFromObject(keyPart, obj){ for (var k in obj){
So this is very close to the jQuery function you have.
(Although a little faster, given that it does not use jQuery and indexOf instead of match )
So what from ~ to indexOf ?
indexOf returns an integer value: -1 if the row is not found, and the index starting at 0 if it is found. (So ββalways a positive integer if found)
~ is the startling NOT , which inverts this output. Be that as it may, the inverted output of indexOf is what we need to indicate βfoundβ or βnot foundβ.
~-1 becomes 0 , a false value.
~x , where x is 0 or fast, becomes -(x+1) , the true value.
So ~string.indexOf('needle') acts like string.contains('needle') , a function that we don't have in JavaScript.
In addition, you can add a binary boolean ( !! ) before ~ to convert the true-ish or false-ish output to the true / false value, but this is not necessary in JavaScript.
Functionally ~string.indexOf('needle') and !!~string.indexOf('needle') are equal.
If you need a start key with a needle, replace:
~k.indexOf(keyPart)
WITH
k.indexOf(keyPart)
source share