[javascript] Objects
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- // ex1
- var rectangle = {
- height: 10,
- width: 5,
- xCoordinate: 3,
- yCoordinate: 5
- }
- for(var prop in rectangle){
- document.write(prop + ": " + rectangle[prop] + "<br>")
- }
- // ex2
- var employee = {
- firstName: "Or",
- lastName: "Hasson",
- salary: 100300,
- phone:"0542121212"
- }
- for(var prop in employee){
- document.write(prop + ": " + employee[prop] + "<br>")
- }
- //ex3
- var clothes = {
- brand: "Nike",
- size: "M",
- color: "Red",
- price: 10
- }
- for(var prop in clothes){
- document.write(prop + ": " +clothes[prop] + "<br>");
- }
- var clothesInput = {
- brand: prompt("Insert the brand:"),
- size: prompt("Insert the size: "),
- color: prompt("Insert the color: "),
- price: +prompt("Insert the price: ")
- }
- for(var prop in clothesInput){
- document.write(prop + ": " +clothesInput[prop] + "<br>");
- }
- //ex4
- var customer = {
- firstName: "Or",
- lastName: "Hasson",
- phone: "054-2226222",
- creditCard: {
- type: "Visa",
- number: "5428-2343-3244-3443",
- expiration: "12/2029",
- cvc: "789"
- }
- }
- for(var prop in customer){
- if(prop === "creditCard"){
- for(var innerProp in customer.creditCard){
- document.write(prop + " ->" + innerProp + ": " + customer.creditCard[innerProp] +"<br>");
- }
- }
- else {
- document.write(prop + ": " + customer[prop] + "<br>");
- }
- }
Editor
You can edit this paste and save as new: