I have an object and I want to iterate over some specific keys of that object. How to achieve this?
Consider the snippet below:
How can I iterate over table1,table2 and table3 keys and not all of them?
var table_object = {
table1: "hello world",
table1_name: "greetings_english.html",
table2: "hola",
table2_name: "greetings_spanish.html",
table3: "Bonjour",
table3_name: "greetings_french.html"
};
You have to specify which keys you have to iterate through:
var table_object = {
table1: "hello world",
table1_name: "greetings_english.html",
table2: "hola",
table2_name: "greetings_spanish.html",
table3: "Bonjour",
table3_name: "greetings_french.html"
};
var keysToIterateThrough = ["table1", "table2", "table3"];
keysToIterateThrough.forEach(key => {
var value = table_object[key];
console.log(`key: ${key} => value: ${value}`);
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With