1

Using Logger.log(response.data.phone), I'm getting this in my log:

[{label=work, primary=true, value=5558675309}, {label=work, value=6108287680, primary=false}, {value=6105516373, label=work, primary=false}]

What I want is to return the two phone numbers as 5558675309, 6108287680.

I've tried Logger.log(response.data.phone.value) and that doesn't work. I've tried ...phone['value'], I've tried ...phone[0].value and this one does return the first phone number 5558675309. But I would like it to return all of the value values whenever I put in the phone key. So how would I modify the logger?

1

2 Answers 2

2

response.data.phone is an array you can try looping through it:

Logger.log(response.data.phone.map(phone => phone.value).join(', '));

const response = {data: {phone : [{label:'work', primary:true, value:5558675309}, {label:'work', value:6108287680, primary:false}, {value:6105516373, label:'work', primary:false}] } }

const Logger = { log : console.log};

Logger.log(response.data.phone.map(phone => phone.value).join(', '));

Sign up to request clarification or add additional context in comments.

Comments

1

response.data is an array, response.data.phone does not exist. What you want is response.data[n].phone for an integer n. You can do this with a forEach loop.

response.data.forEach((element) => Logger.log(element.phone.value));

If for whatever reason you need support for older browsers you can use the older function syntax:

response.data.forEach(function(element){
    Logger.log(element.phone.value)
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.