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

View File

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