Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LukeSkyRunner/dec62259b1b25ffa29637764fe861d62 to your computer and use it in GitHub Desktop.
Save LukeSkyRunner/dec62259b1b25ffa29637764fe861d62 to your computer and use it in GitHub Desktop.
Javascript Nested Data Structure Practice
//Using the given array of objects:
//display price of iPhone,
//display both phones’ names,
//add a new phone at the beginning of the array,
//remove the last element of the array
let products = [
{
name: "iPhone",
price: 799.99
},
{
name: "Samsung Galaxy S10",
price: 900.00
}
]
console.log (products[0].name);
console.log (products[0,1].name);
products.unshift({
name: "Huawei P30",
price: 690.00
})
console.log (products);
products.pop()
console.log (products);
//Given the array, print:
//your course type (full-time or part-time)
//the most familiar topic
//the least familiar topic
let course = {
name: "Web Development",
type: ["full-time", "part-time"],
topics: ["HTML/CSS & Responsive Design", "JavaScript", "MongoDB", "Node", "Express", "React"]
};
console.log (course.type[0]);
console.log (course.topics[0]);
console.log (course.topics[4]);
//Given the object with nested objects in it, print:
let student = {
firstName: "Ana",
lastName: "Blair",
course: {
name: "Web Development",
type: "part-time"
},
attendedIn: "Madrid",
address: {
street: "Happy Street",
number: 123,
city: "Barcelona",
zip: 08015,
country: "Spain"
}
};
console.log(student.course.name);
console.log(student.address.street);
console.log("Ana moved from ",student.address.city," to ",student.attendedIn," to take ",student.course.type,student.course.name," course.")
//Given a 2D array, print the following:
const ironCampuses = [
["Mexico City", "Miami", "Sao Paulo"],
["Amsterdam", "Barcelona", "Berlin", "Lisbon", "Madrid", "Paris"]
];
console.log(ironCampuses[0][1]); // => Miami
console.log(ironCampuses[1][0]); // => Amsterdam
console.log(ironCampuses[1][5]); // => Paris
//Framework sample:
let basic = {
language: "JavaScript",
frameworks: [
{
end: "back",
list: [
{
name: "ExpressJS",
released: 2010
},
{
name: "MeteorJS",
released: 2012
}
]
},
{
end: "front",
list: [
{
name: "ReactJS",
released: 2013
},
{
name: "VueJS",
released: 2014
}
]
}
]
};
//Use the example from the lesson with frameworks to retrieve the following:
console.log(basic.frameworks[0].list[0].name); // => ExpressJS
console.log("In Ironhack, I'll learn",basic.frameworks[0].list[0].name," and ",basic.frameworks[1].list[0].name); // => In Ironhack, I'll learn ExpressJS and ReactJS.
@chiubao
Copy link

chiubao commented Sep 25, 2022

Good
yA6RwSugQFWoVY5vAHMhGF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment