Skip to content

Instantly share code, notes, and snippets.

@colabottles
Created January 8, 2020 13:48
Show Gist options
  • Select an option

  • Save colabottles/3afac46f0e7425a94c2da082adae84ad to your computer and use it in GitHub Desktop.

Select an option

Save colabottles/3afac46f0e7425a94c2da082adae84ad to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/fequfof
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
* {
box-sizing: border-box;
font-size: 1rem;
line-height: 1.5;
}
body {
font-family: 'Open Sans', Arial, Helvetica, sans-serif;
margin: 0 2rem;
}
</style>
</head>
<body>
<p class="sandwiches">Tuna</p>
<p class="sandwiches">Ham</p>
<p class="sandwiches">Turkey</p>
<p class="sandwiches">PB&J</p>
<script id="jsbin-javascript">
var sandwiches = ['turkey', 'tuna', 'ham', 'pb&j'];
// logs 0, tuna, 1, ham, 2, turkey, 3, pb&j
sandwiches.forEach(function (sandwich, index) {
console.log(index) // index
console.log(sandwich) // value
});
// Skip "ham"
// logs 0, tuna, 2, turkey, 3, pb&j
sandwiches.forEach(function (sandwich, index) {
if (sandwich === 'ham') return;
console.log(index); // index
console.log(sandwich); // value
});
</script>
<script id="jsbin-source-css" type="text/css">* {
box-sizing: border-box;
font-size: 1rem;
line-height: 1.5;
}
body {
font-family: 'Open Sans', Arial, Helvetica, sans-serif;
margin: 0 2rem;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">var sandwiches = ['turkey', 'tuna', 'ham', 'pb&j'];
// logs 0, tuna, 1, ham, 2, turkey, 3, pb&j
sandwiches.forEach(function (sandwich, index) {
console.log(index) // index
console.log(sandwich) // value
});
// Skip "ham"
// logs 0, tuna, 2, turkey, 3, pb&j
sandwiches.forEach(function (sandwich, index) {
if (sandwich === 'ham') return;
console.log(index); // index
console.log(sandwich); // value
});
</script></body>
</html>
* {
box-sizing: border-box;
font-size: 1rem;
line-height: 1.5;
}
body {
font-family: 'Open Sans', Arial, Helvetica, sans-serif;
margin: 0 2rem;
}
var sandwiches = ['turkey', 'tuna', 'ham', 'pb&j'];
// logs 0, tuna, 1, ham, 2, turkey, 3, pb&j
sandwiches.forEach(function (sandwich, index) {
console.log(index) // index
console.log(sandwich) // value
});
// Skip "ham"
// logs 0, tuna, 2, turkey, 3, pb&j
sandwiches.forEach(function (sandwich, index) {
if (sandwich === 'ham') return;
console.log(index); // index
console.log(sandwich); // value
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment