Question

In: Computer Science

JavaScript Given the following object, log every property name and value to the console using a...

JavaScript

Given the following object, log every property name and value to the console using a loop.

let myObj = {
    id: 12
    name: 'My Object',
    class: 'obj',
    height: 65,
    likeJavascript: true,
    data: [1, 53, 23]
};
  

Solutions

Expert Solution

Find the code for the above question below, read the comments provided in the code for better understanding. If found helpful please do upvote this.
Please refer to the screenshot of the code to understand the indentation of the code.

To loop a objects use the Object.keys() method , it returns all the keys in an object which can be used to iterate

Code

//Given object

let myObj = {

id: 12,

name: 'My Object',

class: 'obj',

height: 65,

likeJavascript: true,

data: [1, 53, 23]

};

//use the OBject.keys() methods

Object.keys(myObj).forEach(a=>{

//log the key and value

console.log("Property Name : ",a," , Value : ",myObj[a])

})

Screenshot

Output


Related Solutions

Write a log-in log-out session using PHP, CSS, and HTML only. NO MYSQL and JavaScript allowed....
Write a log-in log-out session using PHP, CSS, and HTML only. NO MYSQL and JavaScript allowed. 1. Need an HTML form and a login form; separate file. 2. need a CSS file to make it look good 3. Must store visitors' info in a .txt file and validate from there if the user exists before granting access to the dashboard. If the user does not exist, render the form to signup. If the user exists take them to their dashboard....
Write a recursive method that displays an integer value reversely on the console using the following...
Write a recursive method that displays an integer value reversely on the console using the following header: public static void reverseDisplay(int value) For example, reverseDisplay(12345) displays 54321. Write a test program that prompts the user to enter an integer, invokes the method above, and displays its reversal.
Given the following information regarding an income producing property, determine the net present value using unlevered...
Given the following information regarding an income producing property, determine the net present value using unlevered cash flows at a discount rate of 10%. Expected Holding Period: 5 years; 1st year Expected NOI: $91,200; 2nd year Expected NOI: $93,873; 3rd year Expected NOI: $96,626; 4th year Expected NOI: $99,462; 5th year Expected NOI: $102,383; 6th Expected NOI: 105,634; Debt Service in each of the next five years: $60,544; Current Market Value: $897,000; Required equity investment: $223,350; Apply a going-out capitalization...
Which of the following is/are true about JavaScript object properties? A. To use dot notation, a...
Which of the following is/are true about JavaScript object properties? A. To use dot notation, a property name must be a valid JavaScript identifier B. All properties are automatically locally scoped but may be accessed by using ‘prototype’ C. Variables declared with var inside constructor functions are locally scoped and cannot be directly accessed as properties D. Variables declared with var inside constructor functions are globally scoped E. Properties that contain boolean values may not be accessed with bracket notation...
[Javascript] Create a function(returnObjectFromId(case, ...idNum)) to return the case Object(s) for a given idNum, or list...
[Javascript] Create a function(returnObjectFromId(case, ...idNum)) to return the case Object(s) for a given idNum, or list of idNums. Calling with a single `idNum` value should return the case Object, and return NULL if an id value that's unknown is passed returnObjectFromId(case, 84838) would return the Object in the cases Array with an 'idNumber' of id, and use the .find() method of the cases Array to locate items by idNumber. returnObjectFromId(cases, -23298312) would return null. returnObjectFromId(cases, 161020, 161021) would return an...
Q-1) a client wants to log into a server by using username and password first name...
Q-1) a client wants to log into a server by using username and password first name a suitable http mechanism like cookie or session to make it happen and then make a signal flow diagram to show that how does it happen
C# Write a console application that takes the following passage and removes every instance of the...
C# Write a console application that takes the following passage and removes every instance of the word "not" using StringBuilder and prints the result out to the console: I do not like them In a house. I do not like them With a mouse. I do not like them Here or there. I do not like them Anywhere. I do not like green eggs and ham. I do not like them, Sam-I-am. Ensure that the resulting output reads normally, in...
Javascript Problem: List Reverse Given a list: var list = { value: 1, next: { value:...
Javascript Problem: List Reverse Given a list: var list = { value: 1, next: { value: 2, next: { value: 3, next: null } } }; Reverse the order of the list so that it looks like: var list = { value: 3, next: { value: 2, next: { value: 1, next: null } } }; Use the following shell if needed: //assignment1.js function reverseList(list) { // your code here ... return reversedList; } Example Test Case(s): Arguments: { value:...
Assume the following JavaScript program was interpreted using static-scoping rules. What value of x is displayed...
Assume the following JavaScript program was interpreted using static-scoping rules. What value of x is displayed in function sub1? Under dynamic-scoping rules, what value of x is displayed in function sub1? var x; function sub1() { document.write("x = " + x + ""); } function sub2() { var x; x = 10; sub1(); } x = 5; sub2();
which of the following best describes the mass of an object? a. A physical property and...
which of the following best describes the mass of an object? a. A physical property and intensive property b. A chemical and intensive property c. An intensive and extensive property d. An extensive property and physical property
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT