I am pulling all customer information via an API and printing it in the console.
I am doing this with
if (this.readyState === 4) {
console.log('Body:', this.responseText);
}
};
which gives all of the following data (changed for obvious reasons)
{"id":2,"userIdent":"11","randomInfo":null,"isLead":false,"clientType":1,"companyName":null,"companyRegistrationNumber":null,"companyTaxId":null,"companyWebsite":null,"street1":"1234 Happy Rd","street2":null,"city":"Smile City","countryId":249,"stateId":22,"zipCode":"12345","fullAddress":"1234 Happy Rd, Smile City, MI","invoiceStreet1":null,"invoiceStreet2":null,"invoiceCity":null,"invoiceStateId":null,"invoiceCountryId":null,"invoiceZipCode":null,"invoiceAddressSameAsContact":true,"note":null,"sendInvoiceByPost":null,"invoiceMaturityDays":null,"stopServiceDue":null,"stopServiceDueDays":null,"organizationId":2,"tax1Id":null,"tax2Id":null,"tax3Id":null,"registrationDate":"2022-03-07T00:00:00-0500","leadConvertedAt":null,"companyContactFirstName":null,"companyContactLastName":null,"isActive":false,"firstName":"boop":[],"accountBalance":0.0,"accountCredit":0.0,"accountOutstanding":0.0,"currencyCode":"USD","organizationName":"My Company","bankAccounts":[],"tags":[],"invitationEmailSentDate":null,"avatarColor":"#ef6c00","addressGpsLat":11.22,"addressGpsLon":-22.11,"isArchived":false,"generateProformaInvoices":null,"usesProforma":false,"hasOverdueInvoice":false,"hasOutage":true,"hasSuspendedService":false,"hasServiceWithoutDevices":false,"referral":null}
I only want to pull the value associated with, for example, "userIdent" which would be 11, but I'm not sure how to do this when I'm pulling the data from the api.
CodePudding user response:
You need to add this
var data = JSON.parse(this.responseText);
var userIdent = data['userIdent'];
console.log(userIdent);
CodePudding user response:
const { userIdent } = JSON.parse(this.responseText)
console.log(userIdent) // "11"