This commit is contained in:
Rohit Tanwar
2017-12-31 20:12:34 +05:30
2 changed files with 9 additions and 6 deletions

View File

@ -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;

View File

@ -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
```