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
// JS: map() method | |
let clientes = [ | |
{nombre: "Luis", edad: 22}, | |
{nombre: "Alberto", edad: 31}, | |
{nombre: "Eduardo", edad: 19} | |
]; | |
let foo = clientes.map(function(cliente) { | |
return cliente.nombre; |
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
// JavaScript Function Call | |
let person = { | |
bio: function() { | |
return `Name: ${this.name}, Age: ${this.age}`; | |
} | |
} | |
function greeting(message) { | |
return `${this.name} : ${message}`; |
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
const person = { | |
name: {first:'Bob', last: 'Smith'}, | |
age: 32, | |
gender: 'male', | |
interests: ['Music', 'Boxing'], | |
greeting: function() { | |
console.log(`Hi, I\'m ${this.name.first}`); | |
}, | |
fullName: function() { | |
console.log(`${this.name.first} ${this.name.last}`); |
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
function Person(name) { | |
this.name = name; | |
this.greeting = function() { | |
console.log(`Hi I'm ${this.name}`); | |
} | |
} | |
let person1 = new Person('Peter'); | |
let person2 = new Person('Sarah'); |
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
function Person(name) { | |
this.name = name; | |
this.greeting = function() { | |
console.log(`Hi I'm ${this.name}`); | |
} | |
} | |
let person1 = new Person('Peter'); | |
let person2 = new person1.constructor('Sarah'); |
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
function Person(name) { | |
this.name = name; | |
this.greeting = function() { | |
console.log(`Hi I'm ${this.name}`); | |
} | |
} | |
let person1 = new Person('Peter'); | |
let person2 = new person1.constructor('Sarah'); |
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 requestJSON = 'https://mdn.github.io/learning-area/javascript/oojs/json/superheroes.json'; | |
let request = new XMLHttpRequest(); | |
request.open('GET', requestJSON); | |
request.responseType = 'json'; | |
request.send(); | |
request.onload = function() { | |
let data = request.response; |
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
fetch('https://jsonplaceholder.typicode.com/posts/') | |
.then( | |
function(response) { | |
if (response.status !== 200) { | |
console.log(response.status); | |
return; | |
} | |
response.json().then(function(data) { | |
data.forEach((value, index) => { |
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
fetch("https://jsonplaceholder.typicode.com/posts/") | |
.then(function(response) { | |
if (response.ok) { | |
response.json().then(function(dataJson) { | |
dataJson.forEach((value, index) => { | |
console.log(value.id); | |
console.log(value.title); | |
console.log(value.body); | |
console.log(value.userId); | |
}); |
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
fetch("https://jsonplaceholder.typicode.com/posts/") | |
.then(function(response) { | |
if (response.status !== 200) { | |
console.log('Error en la respuesta HTTP'); | |
return; | |
} | |
return response.json(); | |
}) | |
.then(function(dataJson) { |
OlderNewer