Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a key/value pair for an object

This question may sound very stupid, but I want to get a key/value pair for my object:

var a = {"e":1,"d":3,"f":4}

I tried with Object.keys(a) // returns ["e", "d", "f"]

this does not get me the values associated with the keys, how can I get both to be able to display in a page.

html:

<div>
  <img src={value}/> //here i want value 1 to be displayed
{key} //with "e"
</div>

how do I do it? Thanks!!

like image 201
user1234 Avatar asked Nov 25 '25 12:11

user1234


1 Answers

Here you go. To get key/value pair from an object, do it like below using pure JavaScript way Object.entries():

var a = {"e":1,"d":3,"f":4}

for (const [key, value] of Object.entries(a)) {
  console.log(`${key} ${value}`);
}
like image 187
Vikasdeep Singh Avatar answered Nov 28 '25 02:11

Vikasdeep Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!