Storing object data in variables and then outputting it through printing

My variable called data contains the following information:

var data={
     countrycode: "376",
     dob: "2017-05-24",
     email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e5879687968796a58288848c89cb868a88">[email protected]</a>",
     firstName: "ggsgsggsg",
     gender: "male",
     phoneNumbers: "88888888888888888",
     surName: "hshshhshs"
    }

let countrycode,iso2,number,firstName,surName,dob,gender,email;
countrycode=data.countrycode;
number=data.phoneNumbers;
firstName=data.firstName;
surName=data.surName;
email:data.email;
gender:data.gender;
dob:data.dob;
console.log('email is',email);
console.log('number is ',number);
console.log('gender is',gender);
console.log('surName is',surName);
console.log('dob is',dob);
console.log('firstName is',firstName);

When I try to log these values, I notice that email, gender, and dob return as undefined while the others show the correct values. Why might this be happening?

Answer №1

It is essential to utilize the = sign as an assignment operator in the scenario you presented; colons are specifically used for assigning object properties.

email = data.email;
gender = data.gender;
dob = data.dob;

Answer №2

Make sure to use = for assignment, rather than :, as the latter is specifically used for assigning values to an Object's property.

For example:

email=data.email;

Instead of:

email:data.email;

var data={
     countrycode: "376",
     dob: "2017-05-24",
     email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7614051405140536111b171f1a5815191b">[email protected]</a>",
     firstName: "ggsgsggsg",
     gender: "male",
     phoneNumbers: "88888888888888888",
     surName: "hshshhshs"
    }

let countrycode,iso2,number,firstName,surName,dob,gender,email;
countrycode=data.countrycode;
number=data.phoneNumbers;
firstName=data.firstName;
surName=data.surName;
email=data.email;
gender=data.gender;
dob=data.dob;
console.log('email is ',email);
console.log('number is ',number);
console.log('gender is ',gender);
console.log('surName is ',surName);
console.log('dob is ',dob);
console.log('firstName is ',firstName);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

javascript creating php doesn't function

Greetings! I have an option list in HTML that is being dynamically generated by PHP. My goal is to retrieve the value selected from the option list without having to submit the entire form, and then trigger another PHP function to populate another set of o ...

Three.js Photometric Function

Is there a way to specify a photometric function in Three.js? Currently, I am utilizing a Lambert material: new THREE.MeshLambertMaterial({ color: 0xffffff }) However, I am interested in using a Lommel Seeliger but I am unsure of the process and locatio ...

Step-by-step guide to building multiple layouts in React.js using react-router-dom

For my new web application, I am looking to create two distinct layouts based on the user type. If the user is an admin, they should see the dashboard layout, while employees should be directed to the form layout. Initially, only the login page will be dis ...

Is the order of state variables important in React components?

Upon executing the code below, an error "Cannot read properties of null (reading 'login')" occurs, triggered by reaching the return statement at the end. This error persists despite the presence of checks for the boolean before the return stateme ...

Is it possible for me to incorporate additional functionalities to the scanning process?

I am facing an issue: "How to create a rectangle on mouse down, resize it while moving, and finalize the shape on mouse up". I attempted to solve this using rxjs, but it doesn't seem like the optimal solution: import { scan, mergeMap, takeUntil, fromE ...

Concealing an Automatically Updated Section when Devoid of Content -- Ruby on Rails Version 4

I have come across various solutions to this problem, but none of them seem to be effective for my specific project. In my application, the user's previous choices are displayed in multiple divs. Initially, all the divs are empty. As the user progress ...

Can I programmatically retrieve a comprehensive list of all global HTML attributes available?

Exploring the extensive list of global HTML attributes can be overwhelming, especially when considering how it continues to evolve with browser updates. Can JavaScript be leveraged to dynamically generate a complete list of these attributes without the ne ...

Is there a way to access the userID in the React.js front-end?

As I work on completing my Full Stack Web app with JWT token authentication based on roles, I find myself facing challenges with the front-end development. Specifically, I am unsure of the best practice for retrieving the UserID in the front-end to facil ...

Euro currency formatting

I've been developing a component that formats input values in various currencies like Dollar and Euro, including commas and dots. Although my Dollar input works fine, I'm struggling with the Euro input as it doesn't generate the correct valu ...

Improve code efficiency by streamlining a function and using more effective syntax techniques

I've been learning how to condense code with jQuery. Can this script be written in a more concise manner without everything being on one long line? items.push('<li id="' + key + '">' + ' (key: ' + key + ')&apo ...

An alternative approach to applying multiple filters in AngularJS without using chaining

I am currently facing an issue with using two filters in my ng-repeat. Here is how I have set it up: <tr ng-repeat="c in datasets | filter:filterDataSet | filter:filterExpressionforPerspective | orderBy:'-id'" id="{{c.data_id}}" animate-on-ch ...

I'm looking to arrange the elements in a similar layout as shown in the picture, but I'm unsure of how to do so

https://i.sstatic.net/ku01T.png i'm trying to arrange the elements inside the #gameInpBox similar to the image below body{ margin: 0px; font-family: 'Signika Negative', sans-serif; background-color: #252525; color: #f8f9fa; } . ...

Ionic: setInterval/setTimer not functioning after 5 minutes in the background

In need of a timer that can send notifications via the OneSignal API after a user-defined time period is reached. Users can set the timer for any value between 1-59 minutes. Despite attempts to use the background mode plugin, specifically setInterval and s ...

"Utilizing AJAX for Data Retrieval in a Form with Dynamically Generated

Hey there, I'm trying to figure out how to make my ajax data call dynamic. Here's what I've attempted: var opt_name = $(".NAME").data('opt_name'); var opt_business = $(".BUSINESS").data('opt_business&ap ...

Strategies for refining outputs from Controller within the View

I am facing a challenge where I need to display certain elements in my View and then filter them based on user selection. I attempted to compare variables from the controller result with a JavaScript variable, but unfortunately, it seems that this approach ...

Encountering a problem when trying to send an API request to the server in the latest version of

I am a newcomer to NextJS 13 and I am facing an issue with my files in the app. Despite my efforts to look for solutions online and study tutorials to keep up with the latest updates, I have not been successful in resolving the problem. The endpoint I am ...

Display the element containing the targeted content using jQuery

Is there a way to style all li elements with a specific content without assigning them a unique id or class? <ul class="list"> <li>test</li> <li>test2</li> <li>test</li> </ul> I want to make all ...

Using JQuery Datepicker with an icon and custom format in ASP.NET

I am looking to incorporate jQuery into my Textbox. Specifically, I would like to use the Datepicker with the format yyyy-mm-dd and include an Icon as well. <script> $( "#txtVon" ).datepicker({ showOn: "button", buttonImage: "ima ...

Adding turbolinks to an HTML document can be achieved without the need for a

Recently delving into the world of turbolinks, I discovered that it can be employed independently without relying on a client-side javascript framework. Eager to test this out, I created a bootstrap 4 template and attempted to install it. Firstly, I downl ...

Using Angular.js to Implement Filtering with Intervals

I have implemented a unique custom angular.js filter for formatting datetime objects: function relativeTimeFilter() { return function (dateObj) { return getRelativeDateTimeString(dateObj); }; } function getRelativeDateTimeString(dt) { ...