js loops. associative array
To loop through an associative array in JavaScript, you can use the for...in
loop. Here’s an example:
const myArray = {
"key1": "value1",
"key2": "value2",
"key3": "value3"
};
for (const key in myArray) {
console.log(`Key: ${key}, Value: ${myArray[key]}`);
}
This will output:
Key: key1, Value: value1
Key: key2, Value: value2
Key: key3, Value: value3
In the above example, myArray
is an associative array with three key-value pairs. The for...in
loop iterates over each key in the array and logs the key-value pair to the console.
Test your knowledge with interactive quizzes.
Prepare for interviews with curated question sets.
Ask your coding-related doubts and get answers.
Earn certifications to enhance your resume.
Hands-on projects to improve your skills.
Test your knowledge with interactive quizzes.
Prepare for interviews with curated question sets.
Add your technical blogs and read technical topics.
Earn certifications to enhance your resume.
Hands-on projects to improve your skills.
People Also Asked |
---|