Created
January 16, 2020 02:46
-
-
Save ryandwi/2fd61cf524d4a2355baa118e453b40c6 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/howeyaq
This file contains 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 charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var products = [ | |
{ name: 'cucumber', type: 'vegetable' }, | |
{ name: 'banana', type: 'fruit' }, | |
{ name: 'apple', type: 'fruit' }, | |
{ name: 'orange', type: 'fruit' }, | |
{ name: 'carrot', type: 'vegetable' }, | |
]; | |
// mengunakan for | |
var filteredProduct = [] | |
for (let i = 0; i < products.length; i++) { | |
if (products[i].type === 'fruit') { | |
filteredProduct.push(products[i]) | |
} | |
} | |
// mengunakan filter | |
let fruitProduct = products.filter((product) => product.type === 'fruit') | |
console.log(fruitProduct) | |
// console.log(filteredProduct) | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var products = [ | |
{ name: 'cucumber', type: 'vegetable' }, | |
{ name: 'banana', type: 'fruit' }, | |
{ name: 'apple', type: 'fruit' }, | |
{ name: 'orange', type: 'fruit' }, | |
{ name: 'carrot', type: 'vegetable' }, | |
]; | |
// mengunakan for | |
var filteredProduct = [] | |
for (let i = 0; i < products.length; i++) { | |
if (products[i].type === 'fruit') { | |
filteredProduct.push(products[i]) | |
} | |
} | |
// mengunakan filter | |
let fruitProduct = products.filter((product) => product.type === 'fruit') | |
console.log(fruitProduct) | |
// console.log(filteredProduct)</script></body> | |
</html> |
This file contains 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
var products = [ | |
{ name: 'cucumber', type: 'vegetable' }, | |
{ name: 'banana', type: 'fruit' }, | |
{ name: 'apple', type: 'fruit' }, | |
{ name: 'orange', type: 'fruit' }, | |
{ name: 'carrot', type: 'vegetable' }, | |
]; | |
// mengunakan for | |
var filteredProduct = [] | |
for (let i = 0; i < products.length; i++) { | |
if (products[i].type === 'fruit') { | |
filteredProduct.push(products[i]) | |
} | |
} | |
// mengunakan filter | |
let fruitProduct = products.filter((product) => product.type === 'fruit') | |
console.log(fruitProduct) | |
// console.log(filteredProduct) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment