Created
March 10, 2018 16:06
-
-
Save archiewald/0314c8c50c92fcc7d586093074e570ac to your computer and use it in GitHub Desktop.
JS Bin check a condition on various types // source http://jsbin.com/canipuv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="check a condition on various types"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
//check if array items meet condition | |
//(element && element.length > 0) | |
'use strict'; | |
var array = [undefined, null, ['cos1', 'cos2'], [], 1]; | |
console.log(array.map(function (element) { | |
//!!() transform output to boolean | |
return !!(element && element.length > 0); | |
})); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">//check if array items meet condition | |
//(element && element.length > 0) | |
const array = [ | |
undefined, | |
null, | |
[ | |
'cos1', | |
'cos2' | |
], | |
[], | |
1 | |
]; | |
console.log(array.map((element => { | |
//!!() transform output to boolean | |
return !!(element && element.length > 0) | |
}))) | |
</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//check if array items meet condition | |
//(element && element.length > 0) | |
'use strict'; | |
var array = [undefined, null, ['cos1', 'cos2'], [], 1]; | |
console.log(array.map(function (element) { | |
//!!() transform output to boolean | |
return !!(element && element.length > 0); | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment