add isArrayLike and isValidJSON
This commit is contained in:
21
snippets/isArrayLike.md
Normal file
21
snippets/isArrayLike.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
### isArrayLike
|
||||||
|
|
||||||
|
Checks if the provided argument is `arrayLike` i.e. is iterable.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const arr = (arr) => {
|
||||||
|
try{
|
||||||
|
Array.from(arr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(e){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
isArrayLike(document.querySelector('.className')) // true
|
||||||
|
isArrayLike('abc') // true
|
||||||
|
isArrayLike(null) // false
|
||||||
|
```
|
||||||
21
snippets/isValidJSON.md
Normal file
21
snippets/isValidJSON.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
### isValidJSON
|
||||||
|
|
||||||
|
Checks if the provided argument is an valid JSON.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```js
|
||||||
|
const arr = (obj) => {
|
||||||
|
try{
|
||||||
|
JSON.parse(obj);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(e){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user