Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
46
rated 0 times [  48] [ 2]  / answers: 1 / hits: 23236  / 5 Years ago, sat, august 24, 2019, 12:00:00

I am trying to map the object but in meantime it gives me the following error: TypeError: values.map is not a function. I am new to React development.



I am using this method in Redux method



Code



export function createEvent(values) {
let modifyValue = values.map(newValue => {
return {
subject: newValue.id,
taskType: newValue.tasktype,
time: newValue.time,
date: newValue.date,
notes: newValue.notes,
createdAt: newValue.createdAt,
updatedAt: newValue.updatedAt,
deletedAt: newValue.deletedAt,
userId: newValue.userId,
customerId: localStorage.getItem(customerValue),
start: newValue.start,
end: newValue.end
};
});
return dispatch => {
axios
.post(api/diary/create, modifyValue)

.then(response => {
return dispatch({ type: SET_DIARY_TASK_SUCCESS, data: response });
})

.catch((xhr, status, err) => {
return dispatch({ type: SET_DIARY_TASK_FAILURE, data: xhr });
});
};
}

More From » reactjs

 Answers
20

Array.prototype.map() is using to iterate through array and create new array. If values is a flat object access to it properties explicitly with:



values.propertyName


Your case:



let modifyValue = {
subject: values.id,
taskType: values.tasktype,
time: values.time,
date: values.date,
notes: values.notes,
createdAt: values.createdAt,
updatedAt: values.updatedAt,
deletedAt: values.deletedAt,
userId: values.userId,
customerId: localStorage.getItem(customerValue),
start: values.start,
end: values.end
};

[#51734] Saturday, August 17, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shekinah

Total Points: 699
Total Questions: 112
Total Answers: 110

Location: Philippines
Member since Sat, Jul 11, 2020
4 Years ago
;