Merge branch 'master' of https://github.com/kriadmin/30-seconds-of-code
This commit is contained in:
@ -1,9 +1,11 @@
|
|||||||
### isArrayLike
|
### 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
|
```js
|
||||||
const arr = (arr) => {
|
const isArrayLike = arr => {
|
||||||
try{
|
try{
|
||||||
Array.from(arr);
|
Array.from(arr);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
### isValidJSON
|
### 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
|
```js
|
||||||
const arr = (obj) => {
|
const isValidJSON = obj => {
|
||||||
try{
|
try{
|
||||||
JSON.parse(obj);
|
JSON.parse(obj);
|
||||||
return true;
|
return true;
|
||||||
@ -17,5 +17,6 @@ const arr = (obj) => {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
isValidJSON('{"name":"Adam","age":20}'); // true
|
||||||
|
isValidJSON('{"name":"Adam",age:"20"}'); // false
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user