javascript basic

snowsid88
Tera Contributor

 

Please write a code to print name and number from the below in javascript.

 

{ department : "IT Admin", user details : { {name:"ravi", number:"65839"}, {name:"rahul", number:"44499"} } }

1 ACCEPTED SOLUTION

AJ-TechTrek
Giga Sage
Giga Sage

Hi @snowsid88 ,

 

As per my understanding, here is the code

 

Var data = {
department: "IT Admin",
"user details": [
{ name: "ravi", number: "65839" },
{ name: "rahul", number: "44499" }
]
};

data["user details"].forEach(function(user) {
console.log("Name: " + user.name + ", Number: " + user.number);
});

 

Please appreciate the efforts of community contributors by marking appropriate response as Mark my Answer Helpful or Accept Solution this may help other community users to follow correct solution in future.
 

Thank You
AJ - TechTrek with AJ - ITOM Trainer
LinkedIn:- https://www.linkedin.com/in/ajay-kumar-66a91385/
YouTube:- https://www.youtube.com/@learnitomwithaj
Topmate:- https://topmate.io/aj_techtrekwithaj (Connect for 1-1 Session)
ServiceNow Community MVP 2025

View solution in original post

3 REPLIES 3

Uncle Rob
Kilo Patron

UncleRob_0-1754068297417.png

 

Rafael Batistot
Kilo Patron

Hi @snowsid88 

May you try this

var data = {
  department: "IT Admin",
  user_details: [
    { name: "ravi", number: "65839" },
    { name: "rahul", number: "44499" }
  ]
};

data.user_details.forEach(user => {
  gs.log("Name:", user.name);
  gs.log("Number:", user.number);
});

 

AJ-TechTrek
Giga Sage
Giga Sage

Hi @snowsid88 ,

 

As per my understanding, here is the code

 

Var data = {
department: "IT Admin",
"user details": [
{ name: "ravi", number: "65839" },
{ name: "rahul", number: "44499" }
]
};

data["user details"].forEach(function(user) {
console.log("Name: " + user.name + ", Number: " + user.number);
});

 

Please appreciate the efforts of community contributors by marking appropriate response as Mark my Answer Helpful or Accept Solution this may help other community users to follow correct solution in future.
 

Thank You
AJ - TechTrek with AJ - ITOM Trainer
LinkedIn:- https://www.linkedin.com/in/ajay-kumar-66a91385/
YouTube:- https://www.youtube.com/@learnitomwithaj
Topmate:- https://topmate.io/aj_techtrekwithaj (Connect for 1-1 Session)
ServiceNow Community MVP 2025