Skip to content

Instantly share code, notes, and snippets.

@archiewald
Created March 10, 2018 16:06
Show Gist options
  • Save archiewald/0314c8c50c92fcc7d586093074e570ac to your computer and use it in GitHub Desktop.
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
<!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>
//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