returning objects
Thu Feb 13 2025 02:22:10 GMT+0000 (Coordinated Universal Time)
Saved by
@davidmchale
const courseData = (e) => {
const { currentTarget } = e;
// get all the dataset information
const name = currentTarget?.dataset?.name ?? "";
const id = currentTarget?.dataset?.code ?? "";
const funded = currentTarget?.dataset?.funded ?? "";
const demand = currentTarget?.dataset?.demand ?? "";
const mode = currentTarget?.dataset?.mode ?? "";
const options = currentTarget?.dataset?.training ?? "";
// create object from the current course clicked dataset attributes above
const course = {
courseName: name,
courseId: id,
funding: funded,
demand: demand,
delivery: mode,
training: options,
};
return course;
};
//or
function getListData(data) {
if (!data) return [];
// console.log(data);
return data?.map((item) => ({
name: item?.name ?? "",
category: item?.category ?? "",
web: item?.website ?? "",
tel: item?.tel ?? "",
email: item?.email ?? "",
}));
}
getListData(items);
content_copyCOPY
Comments