I want to extract 10 ids from and object "objectIDs" and put them into an array "idArr". "objectIDs" is an object I get when fetching data (code bellow). The problem is that "objectIDs" is an array? objectIDs[ 0:[array of ids which I want to extract] 1:[another array of ids] 2:[...] .... ] I want to pass 10 of the 0th index ids from objectIDs but don
t seem to be able to as the "idArr" I pass them to looks like [0:ID,1:id,...,10:ID]. And I can`t seem to make use of that array. Would like to find a way to pass the ids from "objectIDs" to "objArr" in the format [ID,ID,ID...,ID]. Is that possible?
let idArr = [];
function getObjectIds() {
fetch("https://collectionapi.metmuseum.org/public/collection/v1/search?hasImages=true&q=early renaissance")
.then(response => response.json())
.then((data) => {
console.log(data);
for (let i = 0; i < 10; i++) {
idArr.unshift(data.objectIDs);
}
})
}
getObjectIds();
console.log(idArr);
Sample data from the link:
{"total":1613,"objectIDs":[199003,22369,207034,208555,436918,390196,387111,480645,460738,459129,206912,437203,21126,10705,12569,438688,207010,75586,386903,363020,437245,468639,436666,468166,696866,386797,386933,386934,35842,23144,436989,196207,196205,196206,436988,195186,461131,460494,459246,25396,193617,21974,206757,462776,505681,437912,813840,437372,436051,436101,201862,459088,437059,193625,193626,186124,505501,460490,468716,467746,204722,472562,503517,186170,471933,471934,337061,197033,195447,437593,447570,468165,201398,202389,202388,459072,473871,676458,428525,236192,460611,23229,210185,191486,460498,25562,25486,25528,25444,207394,458978,467760,435728,201910,445297,5223,195190,468431,203921,201802,460832,460645,207257,474336,435595,202970,201375,192912,437007,195054,197757,471931,471938,471936,471935,471937]}