JS Startup

Challenges, Tips & Tricks & Tutorials

JavaScript Quiz – what is really object entries method return

JavaScript Quiz – what is really object entries method return

Object Entries Method –

JavaScript object entries method ( Object.entries() ) return an array of a given object. In which, object key-value store as nested array values in the main return array. It’s like this –

[ [keyvalue], [keyvalue], … ]

The order of the element in the return does not depend on the object. But you can also short the nested array element for a certain order format.

For more about javascript object entries click here.

JavaScript Question

Now get started, so in this javascript quiz code, you need to find out the value of result[0][1] whose value is assigned using the object entries method bypassing the main object to it.

First, we declare an object variable using let keyword and assign an object to it.

let object = { name : “JS Startup”, work : “JavaScript” };

In the next step, we declare an another variable result using let in which we assign the value return from object entries method and passing object variable in it.

let result = Object.entries(object);

Finally, we are doing console log of particular result value.

console.log(result[0][1]);

It’s time to run your head and find the output of above statement.

Answer – “JS Startup

Click To Run Code

Explanation

Now you get the answer is “JS Startup“. But why you get this that really matters.

So, we assign a value return from the javascript object entries method in which we pass a variable object. So if you console log only result it looks like.

[ [“name”“JS Startup”], [“work”“JavaScript”] ]

Now, as when we access the first element which is at 0 index then you have this.

result[0] = [“name”“JS Startup”]

Last, we access the second element of the nested array and you got the final value.

result[0][1] = “JS Startup”

That’s why we get an answer “JS Startup“.

I hope you understand the concept and logic behind it.

But wait, i have something more for you –

Check out our other javascript quiz – 

  1. JS Quiz – What value should return when adding multiple arrays
  2. JavaScript Quiz – What parseInt function return if pass string
  3. JS Quiz – What happens when add or sub null value
  4. JavaScript Quiz – what really spread syntax with array pushing

Conclusion

To participate in our javascript quiz or challenges, tutorial, tips & tricks make sure to join our jsstartup newsletter. So, you can able to participate in our daily challenges & learn the javascript concept.

And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page

If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top
9 Shares
Share via
Copy link