Skip to content
-
JavaScript Object fromEntries() Method
Last Updated :
12 Jul, 2025
The Object.fromEntries() method in JavaScript is a standard built-in object which is used to transform a list of key-value pairs into an object. This method returns a new object whose properties are given by the entries of the iterable.
Syntax:
Object.fromEntries( iterable )
Parameters: This method accepts a single parameter iterable which holds an iterable such as Array or Map or other objects implementing the iterable protocol.
Return value: This method always returns a new object whose properties are given by the entries of the iterable.
The below examples illustrate the Object.fromEntries() method in JavaScript:
Example 1: In this example, we will convert a Map into an Object using the Object.fromEntries() method in JavaScript.
javascript
const map1 = new Map([['big', 'small'], [1, 0]]);
const geek = Object.fromEntries(map1);
console.log(geek);
const map2 = new Map(
[['Geek1', 'Intern'],
['stipend', 'Works basis']]
);
const geek1 = Object.fromEntries(map2);
console.log(geek1);
Output:
Object { 1: 0, big: "small" }
Object { Geek1: "Intern", stipend: "Works basis" }
Example 2: In this example, we will convert an Array into an Object using the Object.fromEntries() method in JavaScript.
javascript
const arr1 = [['big', 'small'], [1, 0], ['a', 'z']];
const geek = Object.fromEntries(arr1);
console.log(geek);
const arr2 = [['Geek1', 'Intern'], ['stipend', 'Works basis']];
const geek1 = Object.fromEntries(arr2);
console.log(geek1);
Output:
Object { 1: 0, big: "small", a: "z" }
Object { Geek1: "Intern", stipend: "Works basis" }
Example 3: In this example, we will see some other Conversions to objects using Object.fromEntries() method in JavaScript.
javascript
const params = 'type=Get_the Value&geekno=34&paid=10';
const searchParams = new URLSearchParams(params);
console.log(Object.fromEntries(searchParams));
const object1 = { val1: 112, val2: 345, val3: 76 };
const object2 = Object.fromEntries(
Object.entries(object1)
.map(([key, val]) => [key, val * 3])
);
console.log(object2);
Output:
Object { type: "Get_the Value", geekno: "34", paid: "10" }
Object { val1: 336, val2: 1035, val3: 228 }
We have a complete list of Javascript Object methods, to check those please go through this JavaScript Object Complete Reference article.
Supported Browsers: The browsers supported by Object.fromEntries() method are listed below:
- Google Chrome 73 and above
- Firefox 63 and above
- Opera 60 and above
- Safari 12.1 and above
- Edge 79 and above
`;
$(commentSectionTemplate).insertBefore(".article--recommended");
}
loadComments();
});
});
function loadComments() {
if ($("iframe[id*='discuss-iframe']").length top_of_element && top_of_screen articleRecommendedTop && top_of_screen articleRecommendedBottom)) {
if (!isfollowingApiCall) {
isfollowingApiCall = true;
setTimeout(function(){
if (loginData && loginData.isLoggedIn) {
if (loginData.userName !== $('#followAuthor').val()) {
is_following();
} else {
$('.profileCard-profile-picture').css('background-color', '#E7E7E7');
}
} else {
$('.follow-btn').removeClass('hideIt');
}
}, 3000);
}
}
});
}
$(".accordion-header").click(function() {
var arrowIcon = $(this).find('.bottom-arrow-icon');
arrowIcon.toggleClass('rotate180');
});
});
window.isReportArticle = false;
function report_article(){
if (!loginData || !loginData.isLoggedIn) {
const loginModalButton = $('.login-modal-btn')
if (loginModalButton.length) {
loginModalButton.click();
}
return;
}
if(!window.isReportArticle){
//to add loader
$('.report-loader').addClass('spinner');
jQuery('#report_modal_content').load(gfgSiteUrl+'wp-content/themes/iconic-one/report-modal.php', {
PRACTICE_API_URL: practiceAPIURL,
PRACTICE_URL:practiceURL
},function(responseTxt, statusTxt, xhr){
if(statusTxt == "error"){
alert("Error: " + xhr.status + ": " + xhr.statusText);
}
});
}else{
window.scrollTo({ top: 0, behavior: 'smooth' });
$("#report_modal_content").show();
}
}
function closeShareModal() {
const shareOption = document.querySelector('[data-gfg-action="share-article"]');
shareOption.classList.remove("hover_share_menu");
let shareModal = document.querySelector(".hover__share-modal-container");
shareModal && shareModal.remove();
}
function openShareModal() {
closeShareModal(); // Remove existing modal if any
let shareModal = document.querySelector(".three_dot_dropdown_share");
shareModal.appendChild(Object.assign(document.createElement("div"), { className: "hover__share-modal-container" }));
document.querySelector(".hover__share-modal-container").append(
Object.assign(document.createElement('div'), { className: "share__modal" }),
);
document.querySelector(".share__modal").append(Object.assign(document.createElement('h1'), { className: "share__modal-heading" }, { textContent: "Share to" }));
const socialOptions = ["LinkedIn", "WhatsApp","Twitter", "Copy Link"];
socialOptions.forEach((socialOption) => {
const socialContainer = Object.assign(document.createElement('div'), { className: "social__container" });
const icon = Object.assign(document.createElement("div"), { className: `share__icon share__${socialOption.split(" ").join("")}-icon` });
const socialText = Object.assign(document.createElement("span"), { className: "share__option-text" }, { textContent: `${socialOption}` });
const shareLink = (socialOption === "Copy Link") ?
Object.assign(document.createElement('div'), { role: "button", className: "link-container CopyLink" }) :
Object.assign(document.createElement('a'), { className: "link-container" });
if (socialOption === "LinkedIn") {
shareLink.setAttribute('href', `https://www.linkedin.com/sharing/share-offsite/?url=${window.location.href}`);
shareLink.setAttribute('target', '_blank');
}
if (socialOption === "WhatsApp") {
shareLink.setAttribute('href', `https://api.whatsapp.com/send?text=${window.location.href}`);
shareLink.setAttribute('target', "_blank");
}
if (socialOption === "Twitter") {
shareLink.setAttribute('href', `https://twitter.com/intent/tweet?url=${window.location.href}`);
shareLink.setAttribute('target', "_blank");
}
shareLink.append(icon, socialText);
socialContainer.append(shareLink);
document.querySelector(".share__modal").appendChild(socialContainer);
//adding copy url functionality
if(socialOption === "Copy Link") {
shareLink.addEventListener("click", function() {
var tempInput = document.createElement("input");
tempInput.value = window.location.href;
document.body.appendChild(tempInput);
tempInput.select();
tempInput.setSelectionRange(0, 99999); // For mobile devices
document.execCommand('copy');
document.body.removeChild(tempInput);
this.querySelector(".share__option-text").textContent = "Copied"
})
}
});
// document.querySelector(".hover__share-modal-container").addEventListener("mouseover", () => document.querySelector('[data-gfg-action="share-article"]').classList.add("hover_share_menu"));
}
function toggleLikeElementVisibility(selector, show) {
document.querySelector(`.${selector}`).style.display = show ? "block" : "none";
}
function closeKebabMenu(){
document.getElementById("myDropdown").classList.toggle("show");
}