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 –
[ [key, value], [key, value], … ]
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.
First, we declare an object variable using let keyword and assign an object to it.
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.
It’s time to run your head and find the output of above statement.
Now you get the answer is “JS Startup“. But why you get this that really matters.
Now, as when we access the first element which is at 0 index then you have this.
result = [“name”, “JS Startup”]
Last, we access the second element of the nested array and you got the final value.
result = “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 –
- JS Quiz – What value should return when adding multiple arrays
- JS Quiz – What happens when add or sub null value
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.