Answers for "foreach on javasccript object"

1

foreach object javascript

const obj = {
  a: "aa",
  b: "bb",
  c: "cc",
};
//This for loop will loop through all keys in the object.
// You can get the value by calling the key on the object with "[]"
for(let key in obj) {
  console.log(key);
  console.log(obj[key]);
}

//This will return the following:
// a
// aa
// b
// bb
// c
// cc
Posted by: Guest on October-07-2020
-1

js foreach key value

Object.keys(obj).forEach(function (key) {
   // do something with obj[key]
});
Posted by: Guest on March-22-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language