Merge branch 'master' of https://github.com/kriadmin/30-seconds-of-code
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
### isArrayLike
|
||||
|
||||
Checks if the provided argument is `arrayLike` i.e. is iterable.
|
||||
Checks if the provided argument is array-like (i.e. is iterable).
|
||||
|
||||
Use `Array.from()` and a `try... catch` block to check if the provided argument is array-like.
|
||||
|
||||
```js
|
||||
const arr = (arr) => {
|
||||
const isArrayLike = arr => {
|
||||
try{
|
||||
Array.from(arr);
|
||||
return true;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
### isValidJSON
|
||||
|
||||
Checks if the provided argument is an valid JSON.
|
||||
|
||||
Checks if the provided argument is a valid JSON.
|
||||
|
||||
Use `JSON.parse()` and a `try... catch` block to check if the provided argument is a valid JSON.
|
||||
|
||||
```js
|
||||
const arr = (obj) => {
|
||||
const isValidJSON = obj => {
|
||||
try{
|
||||
JSON.parse(obj);
|
||||
return true;
|
||||
@ -17,5 +17,6 @@ const arr = (obj) => {
|
||||
```
|
||||
|
||||
```js
|
||||
|
||||
isValidJSON('{"name":"Adam","age":20}'); // true
|
||||
isValidJSON('{"name":"Adam",age:"20"}'); // false
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user