How to Store an Object sent by a Function in JavaScript ? Last Updated : 23 Feb, 2024 Comments Improve Suggest changes Like Article Like Report When a function in JavaScript returns an object, there are several ways to store this returned object for later use. These objects can be stored in variables, array elements, or properties of other objects. Essentially, any data structure capable of holding values can store the returned object. Table of Content Storing in a variableStoring in an arrayStoring in a variableAssigns the returned object to a variable for direct access within the same scope, offering simplicity and convenience in handling single objects. Example: The below code uses a JavaScript variable to store an object sent by a function in JavaScript. JavaScript function returnObject() { const GFG = { name: "GeeksforGeeks", est: 2009 } return GFG; } const obj = returnObject(); console.log(obj.name, "was established in year:", obj.est); OutputGeeksforGeeks was established in year: 2009 Storing in an arrayInsert the returned object into an array, enabling management of multiple objects in a single data structure, suitable for scenarios requiring collection-based operations. Example: The below code uses an JavaScript array to store an object sent by a function in JavaScript. JavaScript function returnObject() { const GFG = { name: "GeeksforGeeks", est: 2009 } return GFG; } let objArray = []; objArray.push(returnObject()); console.log(objArray[0].name, "was established in year:", objArray[0].est); OutputGeeksforGeeks was established in year: 2009 Comment More infoAdvertise with us Next Article How to Store an Object sent by a Function in JavaScript ? A anjugaeu01 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How a Function Returns an Object in JavaScript ? JavaScript Functions are versatile constructs that can return various values, including objects. Returning objects from functions is a common practice, especially when you want to encapsulate data and behavior into a single entity. In this article, we will see how a function returns an object in Jav 3 min read How to Store a JavaScript Fnction in JSON? In JavaScript, we can store JavaScript functions in JSON objects, allowing us to serialize and store executable code alongside data. we will explore three approaches to store a JavaScript function in JSON. These are the following approaches: Table of Content Using JSON.stringify()Using a Custom toJS 2 min read How to Store an Object Inside an Array in JavaScript ? Storing an object inside an array in JavScript involves placing the object as an element within the array. The array becomes a collection of objects, allowing for convenient organization and manipulation of multiple data structures in a single container. Following are the approaches through which it 3 min read How to print the content of an object in JavaScript ? To print the content of an object in JavaScript we will use JavaScript methods like stringify, object.values and loops to display the required data. Let's first create a JavaScript Object containing some key-values as given below: JavaScript // Given Object const obj = { name: 'John', age: 30, city: 3 min read How to access object properties from result returned by async() function in JavaScript ? In this article, we will see how to access the properties of a javascript object result returned by the async() function in Javascript. A javascript object property is a variable that is associated (read attached) with the object itself, i.e. the properties have a name and value is one of the attrib 3 min read Like