1

I am trying to make an array like value1,value2,value3 that I can iterate through later.

I have the following so far:

var url = 'URL_STRING';

var headers = {
    headers: {
        Username: 'USERNAME',
        "Authorization": "Bearer " + 'KEY'
    },
    contentType: "application/x-www-form-urlencoded",
};

var response = UrlFetchApp.fetch(url, headers);
var json = response.getContentText();

var obj = JSON.parse(json);
var audits = obj.audits;
Logger.log(audits)

The log shows:

[{
    id = value1
}, {
    id = value2
}, {
    id = value3
}]

I thought I would be able to do something like var arr[] = obj.audits.id but this does not work.

1 Answer 1

2

Use map:

const audits =[{
id : "value1"
}, {
id : "value2"
}, {
id : "value3"
}];

const arr = audits.map(({id:v})=>v);
console.log(arr);

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

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.