function ObjectId(id){ return id } let users = [ { "_id": ObjectId("6132882c6facf4dfdd808bda"), "username": "Lolita.Cronin", "password": "UfHige4GqxofPoa", "id": "1", "halls": { "hall0": { "adress": "611 Lorena Corners", "hallname": "praesentium et nihil", "id": "1", "title": "Shazam!" }, "hall1": { "adress": "62507 Jerde Greens", "hallname": "laboriosam qui est", "id": "2", "title": "Captain Marvel" }, "hall2": { "adress": "3773 Rocky Plain", "hallname": "beatae voluptatem in", "id": "3", "title": "Escape Room" }, "hall3": { "adress": "5404 Dovie Road", "hallname": "sunt fugiat quo", "id": "4", "title": "How to Train Your Dragon: The Hidden World" }, "hall4": { "adress": "24624 Myrl Spurs", "hallname": "blanditiis quis sapiente", "id": "5", "title": "Glass" }, "hall5": { "adress": "926 Veum Overpass", "hallname": "veniam exercitationem magnam", "id": "6", "title": "Doraemon the Movie: Nobita's Treasure Island" } } }, { "_id": ObjectId("6132882c6facf4dfdd808bdb"), "username": "Hank20", "password": "BB8KU7iinMI5skg", "id": "2", "halls": { "hall0": { "adress": "53881 Arvid Extension", "hallname": "aut quisquam ut", "id": "7", "title": "Dumbo" }, "hall1": { "adress": "65699 Calista Divide", "hallname": "a quaerat dolor", "id": "8", "title": "Avengers: Infinity War" }, "hall2": { "adress": "2487 Granville Viaduct", "hallname": "***** illum voluptates", "id": "9", "title": "Us" } } }, { "_id": ObjectId("6132882c6facf4dfdd808bdc"), "username": "Kian.Hills48", "password": "AvDbYdDRFP7328e", "id": "3", "halls": { "hall0": { "adress": "34588 Nils Turnpike", "hallname": "aut omnis nemo", "id": "10", "title": "Bumblebee" }, "hall1": { "adress": "5291 Hansen Throughway", "hallname": "iste tenetur sequi", "id": "11", "title": "Cars" } } }, { "_id": ObjectId("6132882c6facf4dfdd808bdd"), "username": "Ernesto67", "password": "eqLzl4D6HwpHF1a", "id": "4", "halls": { "hall0": { "adress": "33033 Helen Estate", "hallname": "sit iste ea", "id": "12", "title": "Avengers: Endgame" }, "hall1": { "adress": "646 Jeffry Port", "hallname": "error atque ut", "id": "13", "title": "Spider-Man: Into the Spider-Verse" }, "hall2": { "adress": "398 Buckridge Creek", "hallname": "assumenda ea blanditiis", "id": "14", "title": "Pet Sematary" } } }, { "_id": ObjectId("6132882c6facf4dfdd808bde"), "username": "Evan_Jakubowski57", "password": "7QhLGmFRNm5gzLl", "id": "5", "halls": { "hall0": { "adress": "727 Wyman Fords", "hallname": "delectus quos consequatur", "id": "15", "title": "Hellboy" }, "hall1": { "adress": "38987 Gilberto Plains", "hallname": "odit corporis voluptas", "id": "16", "title": "After" }, "hall2": { "adress": "7881 Roberts Cliff", "hallname": "atque quod et", "id": "17", "title": "Redcon-1" }, "hall3": { "adress": "93180 Loy Pine", "hallname": "dolore error facilis", "id": "18", "title": "Destroyer" }, "hall4": { "adress": "76331 MacGyver Mill", "hallname": "aut culpa voluptatum", "id": "19", "title": "Mary Poppins Returns" } } }, { "_id": ObjectId("6132882c6facf4dfdd808bdf"), "username": "Brett39", "password": "ZNeCR1YtXQcjatF", "id": "6", "halls": { "hall0": { "adress": "929 Rau Trail", "hallname": "quas aut mollitia", "id": "20", "title": "Shazam!" }, "hall1": { "adress": "1845 Junior Radial", "hallname": "tempore omnis doloremque", "id": "21", "title": "\"Captain Marvel" }, "hall2": { "adress": "636 Kuphal Island", "hallname": "iste molestiae rerum", "id": "22", "title": "Escape Room" } } }, { "_id": ObjectId("6132882c6facf4dfdd808be0"), "username": "Angeline_Cummings38", "password": "8RaPFQXfvzrL7HD", "id": "7", "halls": { "hall0": { "adress": "1734 Olen Keys", "hallname": "nihil velit aut", "id": "23", "title": "How to Train Your Dragon: The Hidden World" }, "hall1": { "adress": "0167 Laila Harbor", "hallname": "molestiae voluptatibus optio", "id": "24", "title": "Glass" }, "hall2": { "adress": "736 Brakus Mills", "hallname": "nemo nobis rerum", "id": "25", "title": "Doraemon the Movie: Nobita's Treasure Island" } } }, { "_id": ObjectId("6132882c6facf4dfdd808be1"), "username": "Ruthie12", "password": "KTTxG0GunjSwTMq", "id": "8", "halls": { "hall0": { "adress": "147 Medhurst Vista", "hallname": "sequi vero et", "id": "26", "title": "Dumbo" }, "hall1": { "adress": "46584 Bailey Key", "hallname": "omnis sunt labore", "id": "27", "title": "Avengers: Infinity War" }, "hall2": { "adress": "89792 Rita Dale", "hallname": "est temporibus molestias", "id": "28", "title": "Us" }, "hall3": { "adress": "13884 Kaya Ridges", "hallname": "ut qui et", "id": "29", "title": "Bumblebee" }, "hall4": { "adress": "85606 Niko Squares", "hallname": "placeat omnis minus", "id": "30", "title": "Avengers: Endgame" } } }, { "_id": ObjectId("6132882c6facf4dfdd808be2"), "username": "Sally75", "password": "HMs1f_AAW0rqQik", "id": "9", "halls": { "hall0": { "adress": "968 Zboncak Trace", "hallname": "blanditiis velit dicta", "id": "31", "title": "Spider-Man: Into the Spider-Verse" }, "hall1": { "adress": "47376 Mac Skyway", "hallname": "neque illum qui", "id": "32", "title": "Guardians of the Galaxy" }, "hall2": { "adress": "1906 Mraz Skyway", "hallname": "quasi eum odit", "id": "33", "title": "Destroyer" }, "hall3": { "adress": "2627 Jones Viaduct", "hallname": "quia rem totam", "id": "34", "title": "Aquaman" }, "hall4": { "adress": "524 Armand Via", "hallname": "ut occaecati quibusdam", "id": "35", "title": "Shazam!" } } }, { "_id": ObjectId("6132882c6facf4dfdd808be3"), "username": "Fidel_Kuhn31", "password": "Hx01gzJRtJxAJXw", "id": "10", "halls": { "hall0": { "adress": "222 Leora Forks", "hallname": "vel nulla distinctio", "id": "36", "title": "Guardians of the Galaxy Vol. 2" }, "hall1": { "adress": "5636 Buckridge Motorway", "hallname": "nostrum nam suscipit", "id": "37", "title": "Captain Marvel" }, "hall2": { "adress": "9228 Thiel Ridges", "hallname": "distinctio veritatis culpa", "id": "38", "title": "Escape Room" } } }, { "_id": ObjectId("6132882c6facf4dfdd808be4"), "username": "Emmett.Effertz", "password": "VFs7xykiyFyUzOR", "id": "11", "halls": { "hall0": { "adress": "610 Gina Mission", "hallname": "saepe ipsa laborum", "id": "39", "title": "Avengers: Infinity War" }, "hall1": { "adress": "245 Zieme Dam", "hallname": "aut animi voluptas", "id": "40", "title": "The Avengers" }, "hall2": { "adress": "64144 MacGyver Key", "hallname": "quis minima atque", "id": "41", "title": "Bumblebee" }, "hall3": { "adress": "80385 Volkman Freeway", "hallname": "explicabo beatae possimus", "id": "42", "title": "Harry Potter and the Philosopher's Stone" }, "hall4": { "adress": "65955 Garfield Gateway", "hallname": "et qui quis", "id": "43", "title": "A Vigilante" }, "hall5": { "adress": "28450 Gottlieb Knolls", "hallname": "odit sequi eveniet", "id": "44", "title": "Thor: Ragnarok" } } }, { "_id": ObjectId("6132882c6facf4dfdd808be5"), "username": "Roscoe_Orn", "password": "NaQiBFlctEcUchb", "id": "12", "halls": { "hall0": { "adress": "4114 Beer Dale", "hallname": "quam repellendus qui", "id": "45", "title": "Avengers: Endgame" }, "hall1": { "adress": "2349 Reba Mall", "hallname": "culpa et fuga", "id": "46", "title": "Spider-Man: Into the Spider-Verse" }, "hall2": { "adress": "490 Lebsack Port", "hallname": "sit ut repellendus", "id": "47", "title": "Black Panther" }, "hall3": { "adress": "31510 Lakin Squares", "hallname": "similique sed velit", "id": "48", "title": "Venom" }, "hall4": { "adress": "439 Demetrius Common", "hallname": "voluptas fuga et", "id": "49", "title": "Incredibles 2" } } }, { "_id": ObjectId("6132882c6facf4dfdd808be6"), "username": "Alfreda.Sawayn", "password": "P7p4pxO31rVtDgq", "id": "13", "halls": { "hall0": { "adress": "0040 Jones Mission", "hallname": "expedita doloribus blanditiis", "id": "50", "title": "Ant-Man and the Wasp" }, "hall1": { "adress": "84820 Hessel Mission", "hallname": "aliquam ut voluptatem", "id": "51", "title": "Jurassic World: Fallen Kingdom" }, "hall2": { "adress": "943 Sidney Plaza", "hallname": "et sit incidunt", "id": "52", "title": "Overlord" }, "hall3": { "adress": "89224 Joshuah Common", "hallname": "neque quia qui", "id": "53", "title": "Inception" } } }, { "_id": ObjectId("6132882c6facf4dfdd808be7"), "username": "Lilliana_Cummings", "password": "XYFqPDVO9uDCoIF", "id": "14", "halls": { "hall0": { "adress": "3486 Donald Trail", "hallname": "minima omnis et", "id": "54", "title": "Ant-Man" }, "hall1": { "adress": "990 Harmon Hill", "hallname": "mollitia inventore qui", "id": "55", "title": "Fifty Shades Freed" }, "hall2": { "adress": "149 MacGyver Junction", "hallname": "ipsa ipse ipsi", "id": "56", "title": "Justice League" }, "hall3": { "adress": "48393 Lori View", "hallname": "velit ex est", "id": "57", "title": "Detective Conan: The Fist of Blue Sapphire" } } }, { "_id": ObjectId("6132882c6facf4dfdd808be8"), "username": "Lora_Zboncak3", "password": "z_9cI8en7SfkkpG", "id": "15", "halls": { "hall0": { "adress": "52180 Schroeder Spur", "hallname": "officia reprehenderit perferendis", "id": "58", "title": "Incredibles 2" }, "hall1": { "adress": "1400 Lukas Cape", "hallname": "ut adipisci odit", "id": "59", "title": "Star Wars: The Last Jedi" }, "hall2": { "adress": "686 Stehr Harbor", "hallname": "tempora asperiores consequuntur", "id": "60", "title": "Deadpool 2" } } }, { "_id": ObjectId("6132882c6facf4dfdd808be9"), "username": "Cristobal1", "password": "bTU6_CxX4fGd1Lz", "id": "16", "halls": { "hall0": { "adress": "99929 Davin Port", "hallname": "cupiditate occaecati eligendi", "id": "61", "title": "Interstellar" }, "hall1": { "adress": "9178 Hansen Drive", "hallname": "aliquam sed atque", "id": "62", "title": "Terminator Genisys" }, "hall2": { "adress": "682 Sally Ville", "hallname": "repellendus at accusantium", "id": "63", "title": "Avengers: Age of Ultron" } } }, { "_id": ObjectId("6132882c6facf4dfdd808bea"), "username": "Myrna93", "password": "hBWqcqfT2tbey47", "id": "17", "halls": { "hall0": { "adress": "806 Mikel Rapids", "hallname": "placeat deleniti neque", "id": "64", "title": "Captain America: Civil War" }, "hall1": { "adress": "2769 Erika Passage", "hallname": "ea dolore optio", "id": "65", "title": "Ant-Man" }, "hall2": { "adress": "083 Bahringer Freeway", "hallname": "nesciunt deserunt deleniti", "id": "66", "title": "Pirates of the Caribbean: The Curse of the Black Pearl" }, "hall3": { "adress": "896 Kovacek Garden", "hallname": "nihil voluptatum qui", "id": "67", "title": "Green Book" }, "hall4": { "adress": "927 Anderson Light", "hallname": "officiis qui rem", "id": "68", "title": "Justice League" } } }, { "_id": ObjectId("6132882c6facf4dfdd808beb"), "username": "Trevor39", "password": "tQ3N5KsUl5eHwkb", "id": "18", "halls": { "hall0": { "adress": "9233 Nelson Village", "hallname": "ut labore ipsum", "id": "69", "title": "Thor: The Dark World" }, "hall1": { "adress": "13842 Telly Extensions", "hallname": "omnis et deserunt", "id": "70", "title": "The Matrix\"" } } }, { "_id": ObjectId("6132882c6facf4dfdd808bec"), "username": "Nicholaus74", "password": "I6SsUbbRaF6jUPZ", "id": "19", "halls": { "hall0": { "adress": "88129 Franecki Fork", "hallname": "architecto nesciunt ipsum", "id": "71", "title": "The Dirt" }, "hall1": { "adress": "695 Josue Forks", "hallname": "nihil et dignissimos", "id": "72", "title": "Steel Country" }, "hall2": { "adress": "2559 Zieme Fords", "hallname": "rem quidem sit", "id": "73", "title": "The Lord of the Rings: The Return of the King" }, "hall3": { "adress": "60936 Willms Heights", "hallname": "rerum laborum omnis", "id": "74", "title": "Alien" } } }, { "_id": ObjectId("6132882c6facf4dfdd808bed"), "username": "Cynthia.Braun35", "password": "kr7annIwu8Gqase", "id": "20", "halls": { "hall0": { "adress": "519 Medhurst Freeway", "hallname": "et alias necessitatibus", "id": "75", "title": "Star Wars: The Force Awakens" }, "hall1": { "adress": "328 Marquardt Land", "hallname": "qui est mollitia", "id": "76", "title": "Deadpool" }, "hall2": { "adress": "4468 Osbaldo Rapid", "hallname": "quam accusantium temporibus", "id": "77", "title": "A Star Is Born" } } }, { "_id": ObjectId("6132882c6facf4dfdd808bee"), "username": "Mac78", "password": "sSJbsyenksr7JRm", "id": "21", "halls": { "hall0": { "adress": "4282 Daniel Station", "hallname": "perspiciatis tenetur quos", "id": "78", "title": "Holmes & Watson" }, "hall1": { "adress": "693 Greenholt Mountain", "hallname": "qui accusamus architecto", "id": "79", "title": "Vice" }, "hall2": { "adress": "4524 Beier Turnpike", "hallname": "officia recusandae sint", "id": "80", "title": "Blade Runner 2049" } } }, { "_id": ObjectId("6132882c6facf4dfdd808bef"), "username": "Ali80", "password": "wkt97wjVrwKT00t", "id": "22", "halls": { "hall0": { "adress": "6583 Roma Shoals", "hallname": "quia non asperiores", "id": "81", "title": "On the Basis of *****" }, "hall1": { "adress": "793 Sasha Junctions", "hallname": "dolore laboriosam deleniti", "id": "82", "title": "Die Hard" }, "hall2": { "adress": "2654 Christian Spring", "hallname": "qui ut voluptatem", "id": "83", "title": "Robin Hood" }, "hall3": { "adress": "0532 Dooley Cliffs", "hallname": "ex fugit magnam", "id": "84", "title": "Split" } } }, { "_id": ObjectId("6132882c6facf4dfdd808bf0"), "username": "Thora.Williamson2", "password": "VXVpGHBCxiM4SFa", "id": "23", "halls": { "hall0": { "adress": "63174 Colten Knolls", "hallname": "non officiis fugiat", "id": "85", "title": "How to Train Your Dragon" }, "hall1": { "adress": "9521 Kristoffer Port", "hallname": "maiores incidunt explicabo", "id": "86", "title": "Spider-Man: Homecoming" }, "hall2": { "adress": "9615 Casper Flats", "hallname": "occaecati ad nesciunt", "id": "87", "title": "The Matrix" }, "hall3": { "adress": "8535 Ivory Radial", "hallname": "rerum doloremque fuga", "id": "88", "title": "The Hard Way" }, "hall4": { "adress": "326 Jamaal Ports", "hallname": "ab qui ducimus", "id": "89", "title": "Justice League" }, "hall5": { "adress": "715 Bashirian Pines", "hallname": "inventore facilis quam", "id": "90", "title": "Pulp Fiction" } } }, { "_id": ObjectId("6132882c6facf4dfdd808bf1"), "username": "Charlotte.Rice71", "password": "0p6QJyu7p_qItuM", "id": "24", "halls": { "hall0": { "adress": "40086 Nettie Burgs", "hallname": "neque odio temporibus", "id": "91", "title": "Fifty Shades Freed" }, "hall1": { "adress": "433 Pascale Shores", "hallname": "a necessitatibus adipisci", "id": "92", "title": "Ant-Man" } } }, { "_id": ObjectId("6132882c6facf4dfdd808bf2"), "username": "Enrique27", "password": "OTm_gOnXw0GCelD", "id": "25", "halls": { "hall0": { "adress": "25813 Rodger Inlet", "hallname": "consequuntur minus consequatur", "id": "93", "title": "Star Wars" }, "hall1": { "adress": "68210 Waters Unions", "hallname": "fugiat est nihil", "id": "94", "title": "Se7en" }, "hall2": { "adress": "422 Ines Roads", "hallname": "tempore est unde", "id": "95", "title": "Inception" }, "hall3": { "adress": "69610 Berge Hills", "hallname": "eius praesentium iste", "id": "96", "title": "Harry Potter and the Half-Blood Prince" }, "hall4": { "adress": "94943 Hermiston Dale", "hallname": "dolores impedit facere", "id": "97", "title": "Iron Man" } } }, { "_id": ObjectId("6132882c6facf4dfdd808bf3"), "username": "Rhiannon73", "password": "ceu5CUNpWUwI1NP", "id": "26", "halls": { "hall0": { "adress": "5159 Kuhn Center", "hallname": "quis eaque optio", "id": "98", "title": "Terminator Genisys" }, "hall1": { "adress": "598 Tina Burg", "hallname": "nisi est ratione", "id": "99", "title": "Overlord" }, "hall2": { "adress": "49682 Jana Courts", "hallname": "quidem a delectus", "id": "100", "title": "Incredibles 2" } } } ] let halls = []; let hallsObject = users.map((user)=>user.halls); for(let hallkey in hallsObject[0]){ halls.push(hallsObject[0][hallkey]); } console.log(halls)
Write, Run & Share Javascript code online using OneCompiler's JS online compiler for free. It's one of the robust, feature-rich online compilers for Javascript language. Getting started with the OneCompiler's Javascript editor is easy and fast. The editor shows sample boilerplate code when you choose language as Javascript and start coding.
Javascript(JS) is a object-oriented programming language which adhere to ECMA Script Standards. Javascript is required to design the behaviour of the web pages.
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function(line){
console.log("Hello, " + line);
});
Keyword | Description | Scope |
---|---|---|
var | Var is used to declare variables(old way of declaring variables) | Function or global scope |
let | let is also used to declare variables(new way) | Global or block Scope |
const | const is used to declare const values. Once the value is assigned, it can not be modified | Global or block Scope |
let greetings = `Hello ${name}`
const msg = `
hello
world!
`
An array is a collection of items or values.
let arrayName = [value1, value2,..etc];
// or
let arrayName = new Array("value1","value2",..etc);
let mobiles = ["iPhone", "Samsung", "Pixel"];
// accessing an array
console.log(mobiles[0]);
// changing an array element
mobiles[3] = "Nokia";
Arrow Functions helps developers to write code in concise way, it’s introduced in ES6.
Arrow functions can be written in multiple ways. Below are couple of ways to use arrow function but it can be written in many other ways as well.
() => expression
const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const squaresOfEvenNumbers = numbers.filter(ele => ele % 2 == 0)
.map(ele => ele ** 2);
console.log(squaresOfEvenNumbers);
let [firstName, lastName] = ['Foo', 'Bar']
let {firstName, lastName} = {
firstName: 'Foo',
lastName: 'Bar'
}
const {
title,
firstName,
lastName,
...rest
} = record;
//Object spread
const post = {
...options,
type: "new"
}
//array spread
const users = [
...adminUsers,
...normalUsers
]
function greetings({ name = 'Foo' } = {}) { //Defaulting name to Foo
console.log(`Hello ${name}!`);
}
greet() // Hello Foo
greet({ name: 'Bar' }) // Hi Bar
IF is used to execute a block of code based on a condition.
if(condition){
// code
}
Else part is used to execute the block of code when the condition fails.
if(condition){
// code
} else {
// code
}
Switch is used to replace nested If-Else statements.
switch(condition){
case 'value1' :
//code
[break;]
case 'value2' :
//code
[break;]
.......
default :
//code
[break;]
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while (condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
ES6 introduced classes along with OOPS concepts in JS. Class is similar to a function which you can think like kind of template which will get called when ever you initialize class.
class className {
constructor() { ... } //Mandatory Class method
method1() { ... }
method2() { ... }
...
}
class Mobile {
constructor(model) {
this.name = model;
}
}
mbl = new Mobile("iPhone");