Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!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">
- //metodos Array filter()
- let almuerzos = [
- {principal: 'arepa', postre:'helado'},
- {principal: 'tacos', postre:'torta de queso'},
- {principal: 'pizza', postre:'galletas'},
- {principal: 'sushi', postre:'quesillo'},
- {principal: 'arepa', postre:'golfeados'},
- {principal: 'arepa', postre:'churros'},
- ];
- /*
- let postresParaPlatosConArepas = [];
- for (let i = 0; i < almuerzos.length; i++) {
- if(almuerzos[i].principal === 'arepa')
- postresParaPlatosConArepas.push(almuerzos[i].postre)
- }
- console.log(postresParaPlatosConArepas);
- */
- let postresParaPlatosConArepas = almuerzos
- .filter((almuerzo) => {
- return almuerzo.principal === 'arepa';
- })
- .map( (almuerzo) => almuerzo.postre)
- console.log(postresParaPlatosConArepas);
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">//metodos Array filter()
- let almuerzos = [
- {principal: 'arepa', postre:'helado'},
- {principal: 'tacos', postre:'torta de queso'},
- {principal: 'pizza', postre:'galletas'},
- {principal: 'sushi', postre:'quesillo'},
- {principal: 'arepa', postre:'golfeados'},
- {principal: 'arepa', postre:'churros'},
- ];
- /*
- let postresParaPlatosConArepas = [];
- for (let i = 0; i < almuerzos.length; i++) {
- if(almuerzos[i].principal === 'arepa')
- postresParaPlatosConArepas.push(almuerzos[i].postre)
- }
- console.log(postresParaPlatosConArepas);
- */
- let postresParaPlatosConArepas = almuerzos
- .filter((almuerzo) => {
- return almuerzo.principal === 'arepa';
- })
- .map( (almuerzo) => almuerzo.postre)
- console.log(postresParaPlatosConArepas);
- </script></body>
- </html>
Add Comment
Please, Sign In to add comment