make use of RegExp.prototype.test()
The test() method executes a search for a match between a regular expression and a specified string. Returns true or false.
function hasNumber(myString) {
return /\d/.test(myString);
}
const output = JSON.stringify(myObject, '\t', 2); | |
//sample | |
var content = JSON.stringify({ | |
test: 2, | |
game: 5 | |
}, '\t', 2); |
function pctToDecimal(percent) { | |
return parseFloat(percent) / 100; | |
} | |
/* | |
pctToDecimal("2xx%") | |
0.02 | |
pctToDecimal("xx%") | |
NaN | |
pctToDecimal("50") |
make use of RegExp.prototype.test()
The test() method executes a search for a match between a regular expression and a specified string. Returns true or false.
function hasNumber(myString) {
return /\d/.test(myString);
}
Examples
window.myConsole = {};
myConsole.log = msg => {
console.log('%c%s', 'color: #fff; background: red; font-size: 14px;', msg);
}
// BAD | |
if ( eventfade.data( "currently" ) !== "showing" ) { | |
eventfade.stop(); | |
} | |
if ( eventhover.data( "currently" ) !== "showing" ) { | |
eventhover.stop(); | |
} | |
if ( spans.data( "currently" ) !== "showing" ) { |
👍🏻 OK
Here's a recap of ways you can reference the jQuery function when the presence of another library creates a conflict over the use of the $ variable:
The jQuery.noConflict() method returns a reference to the jQuery function, so you can capture it in whatever variable you'd like:
.reviewed
If an item is mutable, modifying the copy also modifies the original. If it’s immutable, modifying the copy does not affect the original. It’s confusing because immutable sounds like the item can’t be changed. What it actually means, though, is that the original is not changed when the copy is.
array.splice() mutates the original array, (changes the contents of an array) array.slice() does not mutate the original array (returns a shallow copy)
Mutating: 'array.push()
and array.unshift()
ref="userText" - Vue detects such refs and stores them internally. It basically memorizes that you want access to elements and in your js code you can have access to these elements.
$refs - is an object full of key value pairs where the keys are ref identifiers you set up in your template
ex:
this.message = this.$refs.userText.value;
console.log(this.$refs.userText)
// the whole element will be seen
02/2021
Multiple resources suggest using the Navigator userAgent property to detect mobile devices. However you must take into account that maybe it's not 100% reliable and some devices could give you "false" (I haven't found any problem yet though).
You can use either match or test.
There are alos different ways of doing it but I just used what I think is efficient.
You can also make use of simple media query but there are cases you would prefer not to use that method.